Database opens OK but further calls result in MISUSE

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

Database opens OK but further calls result in MISUSE

James Arthur
Hi

I'm trying to write a SQLite module for BlitzMax (www.blitzmax.com)
and have run in to some difficulty. I've taken the "pure C source"
sqlite-source-3_2_2.zip file and mapped the C functions directly to
Max functions (Max produces *.s code and then uses GCC to compile and
link those and any required *.c/*.cpp files together).

I've started with something fairly simple - opening and closing a database.
---
rc = sqlite3_open("test.db", db)
If Not rc=SQLITE_OK
    Print("Can't open database "+rc)
    sqlite3_close(db)
    End
Else
    Print("Opened: "+rc)
EndIf

Print("Errcode: "+sqlite3_errcode(db))

Print("Closing: "+sqlite3_close(db))
---

That produces the following:
---
Opened: 0
Errcode: 21
Closing: 21
---

So sqlite3_open() is returning sucessfully (the file test.db is
created) but a call to any other sqlite function returns 21
(SQLITE_MISUSE).

I'm still probing around and the problem's almost certainly with the
way Max shares its variables with C code, but from what I can tell of
SQLite, this sort of thing shouldn't happen in a single threaded app.
Maybe someone can make a more informed guess as to why this is
happening?

It seems a little strange that this should happen at all - surely
sqlite3_open() should return 21 as well if there's a problem?

Thanks in advance.

James
Reply | Threaded
Open this post in threaded view
|

Re: Database opens OK but further calls result in MISUSE

Jay Sprenkle
> rc = sqlite3_open("test.db", db)
> If Not rc=SQLITE_OK
>     Print("Can't open database "+rc)
>     sqlite3_close(db)
>     End
> Else
>     Print("Opened: "+rc)
> EndIf
>
> Print("Errcode: "+sqlite3_errcode(db))

Why are you asking for the error code when you already know there was no error?
( this statement: "If Not rc=SQLITE_OK" tells you there was no error )

Are you correctly storing the database handle and passing it to
subsequent functions? (db)
Reply | Threaded
Open this post in threaded view
|

Re: Database opens OK but further calls result in MISUSE

Tiago Dionizio
In reply to this post by James Arthur
On 6/23/05, James Arthur <[hidden email]> wrote:
> I've started with something fairly simple - opening and closing a database.
> ---
> rc = sqlite3_open("test.db", db)

You are not passing the correct arguments to sqlite3_open. The
compiler should have noticed this...

If you are declaring the variable db like "sqlite3 *db;" you have to
call sqlite3_open like:
rc = sqlite3_open("test.db", &db);

That should fix things.

Tiago
Reply | Threaded
Open this post in threaded view
|

Re: Database opens OK but further calls result in MISUSE

Jay Sprenkle
> > ---
> > rc = sqlite3_open("test.db", db)
>
> You are not passing the correct arguments to sqlite3_open. The
> compiler should have noticed this...
>
> If you are declaring the variable db like "sqlite3 *db;" you have to
> call sqlite3_open like:
> rc = sqlite3_open("test.db", &db);
>
> That should fix things.

It's not C code.
Reply | Threaded
Open this post in threaded view
|

Re: Database opens OK but further calls result in MISUSE

James Arthur
In reply to this post by Jay Sprenkle
On 6/24/05, Jay Sprenkle <[hidden email]> wrote:
> Why are you asking for the error code when you already know there was no error?
> ( this statement: "If Not rc=SQLITE_OK" tells you there was no error )

I added the line as a second opinion to make sure it happened with all
other functions.

> Are you correctly storing the database handle and passing it to
> subsequent functions? (db)

Apparently not. The sqlite3_open function was OK, but all the others
weren't - I thought it was the other way around. I sent the email to
the list, went to bed, then when I woke up I knew what was wrong.
Sorry for the trouble.

On the other hand, perhaps I should announce that BlitzMax now
supports SQLite! :)

Cheers

James
Reply | Threaded
Open this post in threaded view
|

Re: Database opens OK but further calls result in MISUSE

Jay Sprenkle
> Apparently not. The sqlite3_open function was OK, but all the others
> weren't - I thought it was the other way around. I sent the email to
> the list, went to bed, then when I woke up I knew what was wrong.
> Sorry for the trouble.

I figure out things in dreams too.

>
> On the other hand, perhaps I should announce that BlitzMax now
> supports SQLite! :)

Congrats!