SQLITE_CANTOPEN using "update" from c++ api

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

SQLITE_CANTOPEN using "update" from c++ api

Christiane Lemke
Hello,

I try to update a row of a Sqlite3 Database with the c++ api using the
following lines of code:

char dbquery[1024];
int rc;
sprintf(dbquery, "update zeit_tabelle set zeit = %d where username like
'%s';", 12345, test);
rc = sqlite3_exec(db, dbquery, 0, 0, 0);

The returned rc is 14, that means SQLITE_CANTOPEN according to the
documentation. Reading the database with "select" querys works perfectly
though. The permissions for the database file itsself are set to 777 in
unix, so everyone is allowed to do anything to it. The update statement
also works using the command line tools, so it should be correct.

Is there any lock I need to aquire to be able to change the database? In
the documentation, it seems as if it would be done automatically... or
is there anything else I am missing?

Any help would be greatly appreciated.

Thanks a lot in advance,

regards, Christiane
Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

Jay Sprenkle
On 10/4/05, Christiane Lemke <[hidden email]> wrote:

>
>
> I try to update a row of a Sqlite3 Database with the c++ api using the
> following lines of code:
>
> char dbquery[1024];
> int rc;
> sprintf(dbquery, "update zeit_tabelle set zeit = %d where username like
> '%s';", 12345, test);
> rc = sqlite3_exec(db, dbquery, 0, 0, 0);



You gave no details.

Did you open the database first?

sqlite3* dbInput = NULL;
int rc = sqlite3_open( dbNameInput.c_str(), &dbInput );
if ( rc )
throw "Can't open source database";

Does zeit_tabelle exist?

Did you bind the variables you're referencing in the update statement?
Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

D. Richard Hipp
In reply to this post by Christiane Lemke
Christiane Lemke <[hidden email]> wrote:

> Hello,
>
> I try to update a row of a Sqlite3 Database with the c++ api using the
> following lines of code:
>
> char dbquery[1024];
> int rc;
> sprintf(dbquery, "update zeit_tabelle set zeit = %d where username like
> '%s';", 12345, test);
> rc = sqlite3_exec(db, dbquery, 0, 0, 0);

Aside: Consider using sqlite3_mprintf with the %Q or %q format strings
to avoid the possibility of buffer overruns and/or SQL injection attacks.

>
> The returned rc is 14, that means SQLITE_CANTOPEN according to the
> documentation. Reading the database with "select" querys works perfectly
> though.

Are you *sure* the database is an SQLite3 database and not an SQLite2
database?
--
D. Richard Hipp <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

Christiane Lemke
In reply to this post by Jay Sprenkle
> You gave no details.
>
> Did you open the database first?

All right, I'm sorry, here is a more complete code snip to illustrate my
problem:


sqlite3 * db;
rc = sqlite3_open("test.db", &db);
if(rc) {
  fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
  exit(1);
}
rc = sqlite3_exec(db, "update usertable set last_access = 1234 where
id_user = 1234", 0, 0, 0);


rc is 14 after these lines. As I said, I can do all kind of "Select"
Queries from the database in the very same program without any problems.

The Query "select id_user, last_access from usertable" returns
id_user = 1234 and last_access = 1128425315, so the table and the
columns exist - the update statement just does not get executed.

Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

Christiane Lemke
In reply to this post by D. Richard Hipp
> Are you *sure* the database is an SQLite3 database and not an SQLite2
> database?

No, I'm not, I have to use a database created somewhere else. How can I
tell?

Anyway, I can open and read the database without any problems with the
sqlite3 C++ API, just modifying does not seem to work.

I can also modify the database using the sqlite3 command line tools, but
it does not work from my program.
Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

D. Richard Hipp
In reply to this post by Christiane Lemke
Christiane Lemke <[hidden email]> wrote:

> > Are you *sure* the database is an SQLite3 database and not an SQLite2
> > database?
>
> No, I'm not, I have to use a database created somewhere else. How can I
> tell?
>
> Anyway, I can open and read the database without any problems with the
> sqlite3 C++ API, just modifying does not seem to work.
>
> I can also modify the database using the sqlite3 command line tools, but
> it does not work from my program.

what operating system?

make sure your /tmp directory is writable.  Also make sure you
are able to create new files in the directory that contains the
database file itself.
--
D. Richard Hipp <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN using "update" from c++ api

Christiane Lemke
> make sure your /tmp directory is writable.  Also make sure you
> are able to create new files in the directory that contains the
> database file itself.

That's it! I did not know that one has to be able to create files in the
directory with the database, I thought the right permissions on the
database file itsself would suffice. I'm sorry for the stupid question.

Thanks a million!

Regards, Christiane