[sqlite] Help with changing the code

2011-04-03 Thread Guilherme Bamepe
Hi! I'm new in SQLite, and I'm studying it to do a work in my college, and would be helpful if I get the SQLite to print, while executing the sql, after each table scan or join, the name of the table and number of rows that are going to the next operator... for example.. the following sql:

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Petite Abeille
On Apr 3, 2011, at 3:18 PM, Marcelo Serrano Zanetti wrote: > It does not work in this way ... could somebody tell me please what is > the correct sintax or whether this is possible at all. As mentioned, SQL is not a procedural language, so, no. That said, you can achieve the same effect with

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Nico Williams
On Sun, Apr 3, 2011 at 3:49 AM, Marcelo S Zanetti wrote: > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT itemID from tabel WHERE item==new ELSE > INSERT INTO table (item) VALUES (new) INSERT INTO t (item) SELECT :new WHERE NOT EXISTS (SELECT item FROM t

[sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo Serrano Zanetti
Hi I would like to do the following I have an item to insert in the table which will be inserted only if this item is not yet in that table otherwise I would like to return the item's key. like that IF 1==SELECT COUNT(*) from table WHERE item==new THEN SELECT itemID from tabel WHERE

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread BareFeetWare
On 03/04/2011, at 6:49 PM, Marcelo S Zanetti wrote: > I have an item to insert in the table which will be inserted only if this > item is not yet in that table otherwise I would like to return the item's key. > > like that > > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo Serrano Zanetti
On 04/03/2011 03:12 PM, Igor Tandetnik wrote: > Marcelo S Zanetti wrote: >> I >> have an item to insert in the table which will be inserted only if this >> item is not yet in that table otherwise I would like to return the >> item's key. >> >> like that >> >> IF 1==SELECT

Re: [sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Paul van Helden
On Sun, Apr 3, 2011 at 3:15 PM, Lynton Grice wrote: > Thanks, issue solved with the following: > > len = sqlite3_column_bytes(stmt,2); > memcpy(msg->raw_stream_in, sqlite3_column_text(stmt, 2), len); > > sqlite3_column_blob is a better function to use.

Re: [sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Igor Tandetnik
Lynton Grice wrote: > Thanks, issue solved with the following: > > len = sqlite3_column_bytes(stmt,2); > memcpy(msg->raw_stream_in, sqlite3_column_text(stmt, 2), len); Actually, you are supposed to use sqlite3_column_blob for binary data. -- Igor Tandetnik

Re: [sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Thanks, issue solved with the following: len = sqlite3_column_bytes(stmt,2); memcpy(msg->raw_stream_in, sqlite3_column_text(stmt, 2), len); Thanks to everyone for your help ;-) Lynton On 03/04/2011 14:52, Paul van Helden wrote: > On Sun, Apr 3, 2011 at 2:46 PM, Lynton >

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Igor Tandetnik
Marcelo S Zanetti wrote: > I > have an item to insert in the table which will be inserted only if this > item is not yet in that table otherwise I would like to return the > item's key. > > like that > > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT itemID

Re: [sqlite] Question:how to insert row with multiple values from same field of different rows of another table?

2011-04-03 Thread Mr. Puneet Kishor
On Apr 3, 2011, at 7:50 AM, Luuk wrote: > On 03-04-2011 14:43, Colin Cuthbert wrote: >> First time I've used this (or any!) mailing list, so sorry if I've done >> something wrong. >> >> Pretty sure my question (in the subect) is phrased badly but it's the best I >> could do! >> >> create

Re: [sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Paul van Helden
On Sun, Apr 3, 2011 at 2:46 PM, Lynton Grice wrote: > char* from SQLite? You say that SELECT treats message as TEXT which is > fine, but then how can I get the FULL payload back into a char* so that > I can write it to a file? > > SELECT doesn't treat the BLOB as

Re: [sqlite] Question:how to insert row with multiple values from same field of different rows of another table?

2011-04-03 Thread Luuk
On 03-04-2011 14:43, Colin Cuthbert wrote: > First time I've used this (or any!) mailing list, so sorry if I've done > something wrong. > > Pretty sure my question (in the subect) is phrased badly but it's the best I > could do! > > create table People(id integer primary key, name text); >

Re: [sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi Michael, Thanks for you feedback, I must say I have learnt something for sure.BUT I still face the problem on how to I READ the BLOB into a char* from SQLite? You say that SELECT treats message as TEXT which is fine, but then how can I get the FULL payload back into a char* so that I

[sqlite] Question:how to insert row with multiple values from same field of different rows of another table?

2011-04-03 Thread Colin Cuthbert
First time I've used this (or any!) mailing list, so sorry if I've done something wrong. Pretty sure my question (in the subect) is phrased badly but it's the best I could do! create table People(id integer primary key, name text); insert into People (name) values ('bob'); insert into People

[sqlite] :Re: sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Black, Michael (IS)
That she blows!!! (to quote Popeye). Your select treats the message as text..and properly truncates at the first nul character. Since it's actuallly binary and NOT text use this: select hex(raw_stream_in) from queue; 4142004445464748494A You also forgot to do select length(raw_stream_in)

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char - FULL CODE

2011-04-03 Thread Black, Michael (IS)
I ran your code with my test file and I get this...which is perfectly correct. Do you get something different? What makes you think the stream is truncated in the database? Also...change SQLITE_STATIC to SQLITE_TRANSIENT...that could be your culprit if you are still seeing truncation. Plus

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi Michael, When I mean't the ".output" I was meaning when I am using the SQLite command line tool, I type in ".output result.txt" and then type "select raw_stream_in from queue;" to stream that result to file. The result file only contains character up until the first NUL. Also, I know it

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char - FULL CODE

2011-04-03 Thread Lynton Grice
Hi Drake, Hi Richard, Hi Paul, Thanks for all your comments, I really appreciate the help. Please see FULL code below. You can literally copy and paste this and compile it with something like: gcc -m64 -Wall -g -I./ -c ./main.c -o ./bigbyte.o gcc -o ./bigbyte ./bigbyte.o -L./ -Wl,-rpath,./

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi Michael, Well to be honest I am trying to mimic an "SAP IDoc (essentially a raw stream) coming out of SAP. In this case the "SAP IDoc" contains a large image, but 99% of the time it is just "plain text". So I probably forgot the "rb", my mistake When I say "point to MSG" I mean I do

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Black, Michael (IS)
How are you trying to view the ouitput.result.txt (and I"ll note that it'sNOT a text file...it's an image according to what you said.). What's the size of the file. And you should be able to post a COMPLETE example to show your testing. What you say you want to do has been done by many

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi Richard, My apologies on the subject line, I did not mean it to say the function is incorrect, but merely to understand why it is chopping it off I am responding to the other now Lynton On 03/04/2011 13:16, Richard Hipp wrote: > Others have responded with requests for information

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi Paul, Yes, I am using fsize as the msg.num_bytes_in.. When I run "SELECT Length(raw_stream_in) FROM test " I get the FULL 13035138 bytes But it I read the "raw_stream_in" and sent it to a file (using ".output result.txt") I only see chars up until the FIRST NUL. Any ideas?

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Richard Hipp
Others have responded with requests for information needed to help track down the root of this problem. (Thanks!) But in the meantime, let me just assure you that your subject line is absolutely, positively incorrect. -- D. Richard Hipp d...@sqlite.org

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Drake Wilson
Quoth Lynton Grice , on 2011-04-03 12:37:06 +0200: > There are NULL characters You mean NUL characters. > in the first couple header fields [...] > > I am no C expert but I have the following table defined: > > char *queueTable = "CREATE TABLE [test] ( " >

[sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi there, I have a 15MB file I need to read and store in an SQLite database. I have attached a file to show you that there are NULL characters in the first couple header fields and the rest is pure BINARY data. But just incase the image gets stipped off while posting you can imagine the file

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Black, Michael (IS)
You apparently don't understand "strings" in C. Or are you actually reading in binary data? #1 Since you said "image" I assume you're reading binaary. So get rid of buffer[fsize]=0. You don't null terminate binary data and that statement is 1-beyond the end of the array (which is from 0 to

Re: [sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Paul van Helden
Hi Lynton, What is the value of msg.num_bytes_in? Is it fsize? And what do you get when you SELECT Length(raw_stream_in) FROM test ? Regards, Paul. ___ sqlite-users mailing list sqlite-users@sqlite.org

[sqlite] sqlite3_bind_blob CHOPS off at first NULL char

2011-04-03 Thread Lynton Grice
Hi there, I have a 15MB file I need to read and store in an SQLite database. There are NULL characters in the first couple header fields and the rest is pure BINARY data. You can imagine the file looking like: ppphNULNUL3STR.and then all the BINARY data.. I am no C expert but I

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo S Zanetti
Hi I would like to do the following I have an item to insert in the table which will be inserted only if this item is not yet in that table otherwise I would like to return the item's key. like that IF 1==SELECT COUNT(*) from table WHERE item==new THEN SELECT itemID from tabel WHERE