SQL statement and C++

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

SQL statement and C++

papa
In this snip, I'd like to show a brief description of what the class
member function should do, in order to ask you if the SQL statement has
been properly prepared.
     sqlite3* db; //!< Data Base
     std::string database_name; //!< The name of the database
     std::string sql_statement_request; //!< Formated SQL request
     sqlite3_stmt* binary_sql_statement; //!< SQL binary statement

     ......
     assign values to the above strings
     ......
     open the database
     .....

     sql_statement_request = database_name + L" \"VACUUM; \" ";
     // Compiled the SQL statement into a byte-code
     rc = sqlite3_prepare_v2(db,
             sql_statement_request.data(),
             -1,
             &binary_sql_statement,
             NULL);

I get an error indicating that binary_sql_statement evaluates to NULL.
I being a SQL with C++ newbie, I'd like to ask much patience from you.
Thanks

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Jens Alfke-2


> On Sep 1, 2017, at 11:23 AM, Papa <[hidden email]> wrote:
>
> I get an error indicating that binary_sql_statement evaluates to NULL.

Most often that means there's a syntax error in the SQL statement.
You should call sqlite3_errcode() to get the error code, and sqlite3_errmsg() to get an error message.

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

papa
Thanks for your suggestion Jens, I tried it and this is what they report.
---------------------------
DEBUGING
---------------------------
sqlite3_extended_errcode == 1
  sqlite3_errcode ==  1
  sqlite3_errmsg == near "F": syntax error

---------------------------
OK
---------------------------

What puzzles me is the report from sqlite3_errmsg, the only thing I can
relate this value F is the directory where the database is being
created, 'F:\Temp' i.e.
std::string database_name;
database_name = "F:\\Temp\\test_database.jdb";
rc = sqlite3_open_v2(
             database_name.c_str(), //Database name
             &db, //Database object
             SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, //
             NULL
             );
On 2017-09-01 2:45 PM, Jens Alfke wrote:

>
>> On Sep 1, 2017, at 11:23 AM, Papa <[hidden email]> wrote:
>>
>> I get an error indicating that binary_sql_statement evaluates to NULL.
> Most often that means there's a syntax error in the SQL statement.
> You should call sqlite3_errcode() to get the error code, and sqlite3_errmsg() to get an error message.
>
> —Jens
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Igor Korot
In reply to this post by papa
Hi,
What are you trying to achieve?
Are you trying to perform a "VACUUM" command on the data base?

Thank you.


On Sep 1, 2017 2:23 PM, "Papa" <[hidden email]> wrote:

In this snip, I'd like to show a brief description of what the class member
function should do, in order to ask you if the SQL statement has been
properly prepared.
    sqlite3* db; //!< Data Base
    std::string database_name; //!< The name of the database
    std::string sql_statement_request; //!< Formated SQL request
    sqlite3_stmt* binary_sql_statement; //!< SQL binary statement

    ......
    assign values to the above strings
    ......
    open the database
    .....

    sql_statement_request = database_name + L" \"VACUUM; \" ";
    // Compiled the SQL statement into a byte-code
    rc = sqlite3_prepare_v2(db,
            sql_statement_request.data(),
            -1,
            &binary_sql_statement,
            NULL);

I get an error indicating that binary_sql_statement evaluates to NULL.
I being a SQL with C++ newbie, I'd like to ask much patience from you.
Thanks

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free
services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

papa
Yes, right after opening the database, I want o perform a vacuuming so
that the new tables can be created, writing and/or read.


On 2017-09-01 4:31 PM, Igor Korot wrote:

> Hi,
> What are you trying to achieve?
> Are you trying to perform a "VACUUM" command on the data base?
>
> Thank you.
>
>
> On Sep 1, 2017 2:23 PM, "Papa" <[hidden email]> wrote:
>
> In this snip, I'd like to show a brief description of what the class member
> function should do, in order to ask you if the SQL statement has been
> properly prepared.
>      sqlite3* db; //!< Data Base
>      std::string database_name; //!< The name of the database
>      std::string sql_statement_request; //!< Formated SQL request
>      sqlite3_stmt* binary_sql_statement; //!< SQL binary statement
>
>      ......
>      assign values to the above strings
>      ......
>      open the database
>      .....
>
>      sql_statement_request = database_name + L" \"VACUUM; \" ";
>      // Compiled the SQL statement into a byte-code
>      rc = sqlite3_prepare_v2(db,
>              sql_statement_request.data(),
>              -1,
>              &binary_sql_statement,
>              NULL);
>
> I get an error indicating that binary_sql_statement evaluates to NULL.
> I being a SQL with C++ newbie, I'd like to ask much patience from you.
> Thanks
>

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Simon Slavin-3
In reply to this post by papa


On 1 Sep 2017, at 9:24pm, Papa <[hidden email]> wrote:

> database_name = "F:\\Temp\\test_database.jdb";

and later

>    sql_statement_request = database_name + L" \"VACUUM; \" ";
>    // Compiled the SQL statement into a byte-code
>    rc = sqlite3_prepare_v2(db,
>            sql_statement_request.data(),
>            -1,
>            &binary_sql_statement,
>            NULL);


you appear to be trying to execute a command with the database name in, something like

> "F:\\Temp\\test_database.jdb "VACUUM"

Why are you trying to execute a command with the database name in ?  The command you want is just VACUUM.  You don’t need any quotes around it and you don’t need the database name as part of the command.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Simon Slavin-3
In reply to this post by papa


On 1 Sep 2017, at 9:47pm, Papa <[hidden email]> wrote:

> Yes, right after opening the database, I want o perform a vacuuming so that the new tables can be created, writing and/or read.

You do not need to execute VACUUM to use new tables.  In fact the command will cause a long delay for no useful result, since you are immediately fragmenting the database again by changing it.  Just proceed without the VACUUM.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Keith Medcalf
In reply to this post by Jens Alfke-2

And look at the oh so usefully provided return code from the prepare call ... there is NO POINT WHATSOEVER in looking at the statement pointer if the return code does not indicate that the prepare prepared anything.  So if the returncode is ANYTHING OTHER THAN SQLITE_OK then you should be expecting the statement pointer to be null.


---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of Jens Alfke
>Sent: Friday, 1 September, 2017 12:46
>To: SQLite mailing list
>Subject: Re: [sqlite] SQL statement and C++
>
>
>
>> On Sep 1, 2017, at 11:23 AM, Papa <[hidden email]> wrote:
>>
>> I get an error indicating that binary_sql_statement evaluates to
>NULL.
>
>Most often that means there's a syntax error in the SQL statement.
>You should call sqlite3_errcode() to get the error code, and
>sqlite3_errmsg() to get an error message.
>
>—Jens
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Jens Alfke-2
In reply to this post by papa


> On Sep 1, 2017, at 1:47 PM, Papa <[hidden email]> wrote:
>
> Yes, right after opening the database, I want o perform a vacuuming so that the new tables can be created, writing and/or read.

I don't know how to put this politely, but you seem to be making things up out of thin air. There's nothing anywhere that says you need to run VACUUM to run any other command. And there are no SQL commands that take the path to the database.

Instead of making things up, try the `sqlite3` command-line tool. Run some SQL commands in that tool's interactive mode and get a feel for how SQL works. Then when you have working commands, you can bring them into your own program.

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQL statement and C++

Simon Slavin-3
In reply to this post by Simon Slavin-3


On 1 Sep 2017, at 9:50pm, Simon Slavin <[hidden email]> wrote:

> you appear to be trying to execute a command with the database name in, something like
>
>> "F:\\Temp\\test_database.jdb "VACUUM"

I’ve just realised what’s going on.  OP has confused the sqlite3 shell tool with what it’s like to use the SQLite API.  The above extract looks like something you might issue to a shell to use the shell tool (which is designed as an interactive exploration aid) as a scripting tool.

Papa, please take a look at this page:

<https://sqlite.org/quickstart.html>

and use the example at the end of the page as a starting point.  Then you might move on to this page:

<https://sqlite.org/cintro.html>

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users