[sqlite] DB file locked when no other process using it

2010-09-14 Thread Andrew Wood
Im getting an error saying the database is locked even though no other 
process is accessing the file. I think it was probably caused by a 
process crashing part way through. Is there a way to force release the lock?

Andrew

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Detecting storage class from C

2010-09-10 Thread Andrew Wood
On 09/09/10 00:01, Igor Tandetnik wrote:
> No. sqlite3_column_type returns the type of the value in the given column and 
> the current row. The type reported by sqlite3_column_type may change from row 
> to row. It is largely unrelated to the type "you originally intended the 
> column to be" (SQLite doesn't really have such a concept; column affinity 
> comes closest, but there's no API to report it, directly).
>
> In particular, if the value in the current row is null, sqlite3_column_type 
> returns SQLITE_NULL.
>
Exactlybut

On 09/09/10 00:07, Nicolas Williams wrote:
> You can use CHECK() expressions to ensure all values are of the intended
> type, and you can use NOT NULL to avoid NULL (or treat NULL as being of
> whatever type sqlite3_column_type() reports).
>
>
There may be a nugget of a solution here. I'll do some experimenting.


One related question. The library Im using maps numeric types to one of 
the following C types:

unsigned long int
signed long int
unsigned int (short)
signed int (short)
float
double

How does SQLite distinguish between ordinary floats and doubles, and 
between long & short ints, and signed or unsigned ints?

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Detecting storage class from C

2010-09-08 Thread Andrew Wood
Because I'm writing glue code between the SQLite API and a higher level 
library which provides a standard API across several DBMSs.

  In other DBMSs even if a field contains null you can still ask the API 
what type it 'should' have been if something *had* been put in it. 
Without this ability, I cant make SQLite work with the library.

I don't understand the reasoning for designing SQLite weakly typed like 
this, it just seems bizarre.

On 02/09/10 14:28, Pavel Ivanov wrote:
>> My reason for doing this is, if a field is null, I still need to know
>> what class it 'should' have been if it had been storing a value.
>>  
> Why do you need that? No matter what you declare field can store any
> type of data. And in SQLite there's no "declared storage class". You
> are talking either about "affinity", or "declared column type", or
> "actual data type stored'. So which one of those 3 exactly you want to
> know and why?
>
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Detecting storage class from C

2010-09-02 Thread Andrew Wood
Yes but none of those functions return the class that the declared type 
maps to (SQLITE_TEXT, SQLITE_FLOAT etc), they just return the SQL type 
as a string, of which there are umpteen possibilities.


Presumably then Im going to have to map them to the class myself? My 
question was, is this the case, or is there some other function in the 
API that will do this for me that Ive overlooked?

My reason for doing this is, if a field is null, I still need to know 
what class it 'should' have been if it had been storing a value.


On 31/08/10 02:58, Roger Binns wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 08/31/2010 06:33 AM, Andrew Wood wrote:
>
>> I need to detect the declared storage class of a field rather than the
>> actual type stored, but as I understand it sqlite3_column_decltype
>> returns the SQL type not the SQLite storage class? Is there a way to get
>> this info?
>>  
> http://www.sqlite.org/c3ref/column_blob.html
>
> Roger
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkx8Yb0ACgkQmOOfHg372QTp4wCeKIQzs1RD0E51ZT94bUoMMRWA
> rqcAnjID6Fklsj1cPBQwCVHjXQxLZuu+
> =Bscw
> -END PGP SIGNATURE-
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
> __
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> __
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Books which cover C API

2010-07-08 Thread Andrew Wood
Id seen the book page but wasnt sure which one covered the C API the 
best. Ill try the APress one for now, thanks for the tip.

On 07/07/10 19:55, Jay A. Kreibich wrote:
> On Wed, Jul 07, 2010 at 07:45:02PM +0100, Andrew Wood scratched on the wall:
>
>> Which of the books on the market is the best for covering the C API?
>>  
>http://sqlite.org/books.html
>
>
>
>
>If you want to go out and buy something today, the most popular book
>is "The Definitive Guide to SQLite" by Mike Owens.  It is a bit
>older, but the core APIs haven't really changed:
>
> http://www.amazon.com/Definitive-Guide-SQLite-Mike-Owens/dp/1590596730/
>
>
>
>This one is coming out next month.  I like it.
>
> http://www.amazon.com/Using-SQLite-Jay-Kreibich/dp/0596521189/
>
>
> -j
>
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Getting declared datatype of a column in C

2010-07-08 Thread Andrew Wood
Just thought of something else.

Even if I fix the way a blob is inserted so that it causes it to be 
correctly detected  as a blob by sqlite3_column_type() theres still a 
problem -  because if a field comes back as SQLITE_NULL my application 
still needs to know what type the field was supposed to be.




On 07/07/10 15:31, Jay A. Kreibich wrote:
> On Wed, Jul 07, 2010 at 02:35:58PM +0100, Andrew Wood scratched on the wall:
>
>> Ok, what if I come at the problem from the opposite side:
>>
>> The problem is, Ive got a BLOB field which contains  a char array as an
>> escpaped string but when I call sqlite3_column_type(preparedstatement,
>> x); it comes back as SQLITE_TEXT not SQLITE_BLOB
>>  
>It sounds like it is being inserted as a text value (or you're
>calling sqlite3_column_bytes16() or something silly).  Try
>selecting typeof(col) and see what that returns.
>
>If you're inserting literal values, BLOBs must be in hex.  For
>example, these will both insert the same three bytes
>(ASCII 'A' = 0x41):
>
>
>  X'414243'is a BLOB value.
>   'ABC'   is a text value.
>
>
>  -j
>
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Books which cover C API

2010-07-07 Thread Andrew Wood
Which of the books on the market is the best for covering the C API?


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Getting declared datatype of a column in C

2010-07-07 Thread Andrew Wood
Ok, what if I come at the problem from the opposite side:

The problem is, Ive got a BLOB field which contains  a char array as an 
escpaped string but when I call sqlite3_column_type(preparedstatement, 
x); it comes back as SQLITE_TEXT not SQLITE_BLOB

I want a way to detect that it should really be a blob not a string so 
that its interpreted as a char array rather than just a regular string. 
I seem to recall in MySQL you can check this by testing the charset of 
the string.

On 07/07/10 13:37, Jay A. Kreibich wrote:
> On Wed, Jul 07, 2010 at 12:32:53PM +0100, Andrew Wood scratched on the wall:
>
>> Is there not just a function which will take the index of a column and
>> return its declared type?
>>  
>Not in the general case.  sqlite3_column_decltype() will do it for
>SELECT statements, but only if the result-set column is a direct
>column reference, and only if SQLite is compiled to handle meta-data.
>
>Declared types are fairly unimportant in SQLite.  They don't mean
>much.  Most applications never need to deal with them.
>
> -j
>
>
>> On 07/07/10 04:41, Jay A. Kreibich wrote:
>>  
>>> On Tue, Jul 06, 2010 at 11:27:09PM +0100, Andrew Wood scratched on the wall:
>>>
>>>
>>>> How can I find out the declared type of a column.
>>>>
>>>>  
>>> If you just want to know the declared type of a column you already
>>> know about, it use "PRAGMA table_info".
>>>
>>> http://www.sqlite.org/pragma.html
>>>
>>>  -j
>>>
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Getting declared datatype of a column in C

2010-07-07 Thread Andrew Wood
Is there not just a function which will take the index of a column and 
return its declared type?

On 07/07/10 04:41, Jay A. Kreibich wrote:
> On Tue, Jul 06, 2010 at 11:27:09PM +0100, Andrew Wood scratched on the wall:
>
>> Ive been looking at the function
>>
>> sqlite3_column_decltype
>>
>> and am a little confused as to its use.
>>
>> How can I find out the declared type of a column.
>>  
>If you just want to know the declared type of a column you already
>know about, it use "PRAGMA table_info".
>
>http://www.sqlite.org/pragma.html
>
> -j
>
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Getting declared datatype of a column in C

2010-07-06 Thread Andrew Wood
Ive been looking at the function

sqlite3_column_decltype

and am a little confused as to its use.

How can I find out the declared type of a column.

As I understand this function, I would have to do a single col select first, 
(select col1 from table) then pass that prepared statement to ?  
sqlite3_column_decltype

Then for the second col change the query to "select col2 from table" and repeat.

Surely theres a quicker way?



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Use of sqlite3_step()

2010-07-06 Thread Andrew Wood
Whoops thats what comes of writing code when you're feeling under weather :)

Thanks

On 06/07/10 16:43, Mike Shal wrote:
>
> I haven't tried it, but I suspect this is your problem. It looks like
> you're declaring a new 'queryreturn' int, but the while loop is
> checking against the one from the top of the program. You can probably
> just remove the 'int' here.
>
> -Mike
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
> __
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> __
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Use of sqlite3_step()

2010-07-06 Thread Andrew Wood
Whats the procedure for using sqlite3_step?

I thought it would be along the lines of the following, but the while 
loop executes infinately. I would have expected the while loop to run 
once for each row found?

Code is as follows:

int queryreturn = sqlite3_step(preparedstatement);

if (queryreturn == SQLITE_DONE)
 {
 //no rows found
 return;

 }
 else if (queryreturn == SQLITE_ROW)
 {
 //row found, will process in a sec
 }
 else
 {
 //error, throw exception

 }
 //if we get here we have 1 or more rows to process

 while (queryreturn==SQLITE_ROW)
 {//process row
 printf("row found\n");

 //advance to next row
 int queryreturn = sqlite3_step(preparedstatement);
 }
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Escaping binary data

2010-07-02 Thread Andrew Wood

Thank you


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Escaping binary data

2010-07-01 Thread Andrew Wood
I apologise if this is in the documentation but I cant seem to follow it.

Is there a function in the C/C++ API which will escape an array of 
binary data. For example in MySQL there is the following function:

mysql_real_escape_string(,out,in,length);

What Id like to do is take a char array in C, escpape it and drop it 
into a plain text SQL string which could then be passed to 
sqlite3_get_table()

Thanks
Andrew

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users