[sqlite] is updating Blobs different than inserting??

2008-03-19 Thread C S
hi all. wondering if there is any difference in
updating blobs vs inserting? for instance if you have
a small blob and when you update the blob increases in
size and also going from larger to smaller. 

is there anything special that i need to check for or
do to make sure i dont lose any data? 

thanks!


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
hey i wanted to thank Igor, Ron, Dennis and Matthew
(sorry if i forgot anyone else) with helping me with
this blob stuff.
-cheers

c.s.
--- Igor Tandetnik <[EMAIL PROTECTED]> wrote:

> C S <[EMAIL PROTECTED]> wrote:
> > -so it seems that despite my byte order being
> wrong?,
> > i get the output back out exactly how i stored it
> in
> > the original array.
> 
> There is nothing wrong with the byte order. It
> matches the native order 
> of your CPU.
> 
> > is there a problem here i should
> > be concerned about in the long run or why i should
> > change the order?
> 
> If you ever need to have the database file portable
> between machines 
> with different architecture (e.g. Intel Mac vs
> PowerPC Mac) you will 
> have to think about this endianness problem.
> 
> > i am running on a Linux Ubuntu machine.
> 
> The operating system is largely irrelevant. What's
> important is what 
> hardware you are running on.
> 
> Igor Tandetnik 
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Ron - 

this is my select statement:
 
sqlite> select imageID, hex(imageData) from Images;
1|0300060009000C000F001200150018001B00
2|010002000300040005000600070008000900
3|010002000300040005000600070008000900

-sorry for the confusion i was just copying and
pasting wrong. looks like everything looks fine if you
were to space these out. 


--- "Wilson, Ron P"
<[EMAIL PROTECTED]> wrote:

> you are delimiting your dwords wrong.  reverse the
> byte order.  this
> resolves your leading and trailing 00 problem.
> 
> sqlite> select imageID, hex(imageData) from Images;
> 1| 0300 0600 0900 0C00 0F00 1200 1500 1800 1B00
> 2| 0100 0200 0300 0400 0500 0600 0700 0800 0900
> 3| 0100 0200 0300 0400 0500 0600 0700 0800 0900
> *** 
> 
> RW
> 
> Ron Wilson, S/W Systems Engineer III, Tyco
> Electronics, 434.455.6453
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of C S
> Sent: Wednesday, March 12, 2008 12:07 PM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] SQL Blobs - what am i doing
> wrong here?(code
> inside)
> 
> Igor,
> 
>   thanks for all your help too man. here is what is
> in
> the table images so far when i do a select. its 3
> blobs:
> 
> sqlite> select imageID, hex(imageData) from Images;
> 1|00 0003 0006 0009 000C 000F 0012 0015 0018 001B 00
> 2|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
> 3|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
>
*
> 
> here is what i have now:
> 
> const unsigned short *image;
> int i = 0;
> 
> myString2 = "select imageID, imageData from Images";
> 
> int status = sqlite3_prepare_v2(db, update.c_str(),
> -1, , NULL);
> 
>  while ((status = sqlite3_step(statement)) ==
> SQLITE_ROW)
>{
> i++
> 
> if(i == 1)
>   std::cout << "first row" << std::endl;
> 
> else std::cout << "another row" << std::endl;
> 
> num_bytes = sqlite3_column_bytes(statement, i);
> num_bytes = num_bytes / sizeof(unsigned short);
> image = new unsigned short[num_bytes];
> image = (const unsigned
> short*)sqlite3_column_blob(statement, i);
> 
> for(int i = 0; i < num_bytes; i++)
>std::cout << "image " << i << ": " <<
> image[i]
> << std::endl;
> 
> //delete [] image; //causes a crash so far. 
>}
> 
>  status = sqlite3_finalize(statement);
>  if (status != SQLITE_OK)
>  std::cerr << "Error deleting prepared SQL
> statement" << std::endl;
> 
>  else std::cout << "finalized statement
> successfully"
> << std::endl;
> 
> ***
> 
> Output:
> 
> first row
> image 0: 0
> image 1: 3
> image 2: 6
> image 3: 9
> image 4: 12
> image 5: 15
> image 6: 18
> image 7: 21
> image 8: 24
> image 9: 27
> another row
> another row
> finalized statement successfully
> 
> --so for some reason i get the first
> blob(successfully, yes!) but it never increments
> after
> that. the statement is also finalized successfully.
> any reason why the other two blobs are not printing
> out? 
> 
> as a side note i commented out the deleting of the
> image because i got a major abort crash, no doubt
> memory leaks/forbidden access issues. 
> 
> thanks!! 
> 
> 
> 
> 
> 
> 
> --- Igor Tandetnik <[EMAIL PROTECTED]> wrote:
> 
> > C S <[EMAIL PROTECTED]> wrote:
> > >  thanks for the tip on the hex. now i can see my
> > > entry of the blob. my original loop to fill the
> > > dynamic array with unsigned shorts was this:
> > >
> > > imageArray = new unsigned short[10];
> > >
> > > for(int i = 0; i < 10; i++)
> > >  imageArray[i] = i;
> > >
> > > so now if i run the program then do a:
> > >
> > > select imageID, hex(imageData) from Images;
> > >
> > > i get the result:
> > >
> > > 1|010002000300040005000600070008000900
> > >
> > > i am not sure where the first 2 leading zeros
> are
> > > coming from
> > 
> > The first value (the one at index 0) in imageArray
> > is zero, represented 
> > by two zero bytes.
> > 
> > > now i need to be able to extract the data back
> out
> > of
> &g

Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Igor,

  haha i JUST changed this before i checked your email
to:

while ((status = sqlite3_step(statement)) ==
SQLITE_ROW)
   {
std::cout << "status is: " << status <<
std::endl;
i++;
if(i == 1)
 std::cout << "first row" << std::endl;
else
  std::cout << "another row" << std::endl;
num_bytes = sqlite3_column_bytes(statement,
1);
num_bytes = num_bytes / sizeof(unsigned
short);
image = new unsigned short[num_bytes];
image = (const unsigned
short*)sqlite3_column_blob(statement, 1);

 for(int j = 0; j < num_bytes; j++)
   std::cout << "image " << j << ": " << image[j]
<< std::endl;
**

so i get the output correct back out now: 

Output --

first row
image 0: 0
image 1: 3
image 2: 6
image 3: 9
image 4: 12
image 5: 15
image 6: 18
image 7: 21
image 8: 24
image 9: 27
another row
image 0: 0
image 1: 1
image 2: 2
image 3: 3
image 4: 4
image 5: 5
image 6: 6
image 7: 7
image 8: 8
image 9: 9
another row
image 0: 0
image 1: 1
image 2: 2
image 3: 3
image 4: 4
image 5: 5
image 6: 6
image 7: 7
image 8: 8
image 9: 9
***

-so it seems that despite my byte order being wrong?,
i get the output back out exactly how i stored it in
the original array. is there a problem here i should
be concerned about in the long run or why i should
change the order? 

would like your response -- thanks!

oh yeah - 

i am running on a Linux Ubuntu machine. the only big
endian machines now a days that i can think of are old
SGI's(didnt they switch to intel) and old mac's(which
now use intel(little endian)). 

*


--- Igor Tandetnik <[EMAIL PROTECTED]> wrote:

> C S <[EMAIL PROTECTED]> wrote:
> >  thanks for all your help too man. here is what is
> in
> > the table images so far when i do a select. its 3
> > blobs:
> >
> > sqlite> select imageID, hex(imageData) from
> Images;
> > 1|00 0003 0006 0009 000C 000F 0012 0015 0018 001B
> 00
> > 2|00 0001 0002 0003 0004 0005 0006 0007 0008 0009
> 00
> > 3|00 0001 0002 0003 0004 0005 0006 0007 0008 0009
> 00
> >
>
*
> 
> I bet you are running on a little-endian machine. On
> such a machine, the 
> low-order byte comes first. So the correct breakdown
> is
> 
> 1| 0300 0600 0900 0C00 0F00 1200 1500 1800 1B00
> 
> For example, two bytes 0300 represent a two-byte
> integer 3 in 
> little-endian (least-significant byte first,
> most-significant last).
> 
> > while ((status = sqlite3_step(statement)) ==
> > SQLITE_ROW)
> >   {
> >i++
> >
> >num_bytes = sqlite3_column_bytes(statement, i);
> 
> 'i' refers to the row index, and is incremented with
> each step. The last 
> parameter to sqlite3_column_bytes is a _column_
> index: it doesn't change 
> as you scan through rows. You always pass 0 to
> retrieve the first column 
> (from the current row, whatever it happens to be), 1
> to retrieve the 
> second column and so on.
> 
> Your code just accidentally happens to pass a
> correct column index for 
> the first row, but wrong index for all subsequent
> rows.
> 
> Igor Tandetnik 
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
replying to my own message - 

update should my myString2 - that is not an actual
error, just copied and pasted it wrong. also i noticed
a problem with i in my final for loop. i changed it to
j since i was being incremented. i still get the same
output however. just to clarify. 

--- C S <[EMAIL PROTECTED]> wrote:

> Igor,
> 
>   thanks for all your help too man. here is what is
> in
> the table images so far when i do a select. its 3
> blobs:
> 
> sqlite> select imageID, hex(imageData) from Images;
> 1|00 0003 0006 0009 000C 000F 0012 0015 0018 001B 00
> 2|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
> 3|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
>
*
> 
> here is what i have now:
> 
> const unsigned short *image;
> int i = 0;
> 
> myString2 = "select imageID, imageData from Images";
> 
> int status = sqlite3_prepare_v2(db, update.c_str(),
> -1, , NULL);
> 
>  while ((status = sqlite3_step(statement)) ==
> SQLITE_ROW)
>{
> i++
> 
> if(i == 1)
>   std::cout << "first row" << std::endl;
> 
> else std::cout << "another row" << std::endl;
> 
> num_bytes = sqlite3_column_bytes(statement, i);
> num_bytes = num_bytes / sizeof(unsigned short);
> image = new unsigned short[num_bytes];
> image = (const unsigned
> short*)sqlite3_column_blob(statement, i);
> 
> for(int i = 0; i < num_bytes; i++)
>std::cout << "image " << i << ": " <<
> image[i]
> << std::endl;
> 
> //delete [] image; //causes a crash so far. 
>}
> 
>  status = sqlite3_finalize(statement);
>  if (status != SQLITE_OK)
>  std::cerr << "Error deleting prepared SQL
> statement" << std::endl;
> 
>  else std::cout << "finalized statement
> successfully"
> << std::endl;
> 
> ***
> 
> Output:
> 
> first row
> image 0: 0
> image 1: 3
> image 2: 6
> image 3: 9
> image 4: 12
> image 5: 15
> image 6: 18
> image 7: 21
> image 8: 24
> image 9: 27
> another row
> another row
> finalized statement successfully
> 
> --so for some reason i get the first
> blob(successfully, yes!) but it never increments
> after
> that. the statement is also finalized successfully.
> any reason why the other two blobs are not printing
> out? 
> 
> as a side note i commented out the deleting of the
> image because i got a major abort crash, no doubt
> memory leaks/forbidden access issues. 
> 
> thanks!! 
> 
> 
> 
> 
> 
> 
> --- Igor Tandetnik <[EMAIL PROTECTED]> wrote:
> 
> > C S <[EMAIL PROTECTED]> wrote:
> > >  thanks for the tip on the hex. now i can see my
> > > entry of the blob. my original loop to fill the
> > > dynamic array with unsigned shorts was this:
> > >
> > > imageArray = new unsigned short[10];
> > >
> > > for(int i = 0; i < 10; i++)
> > >  imageArray[i] = i;
> > >
> > > so now if i run the program then do a:
> > >
> > > select imageID, hex(imageData) from Images;
> > >
> > > i get the result:
> > >
> > > 1|010002000300040005000600070008000900
> > >
> > > i am not sure where the first 2 leading zeros
> are
> > > coming from
> > 
> > The first value (the one at index 0) in imageArray
> > is zero, represented 
> > by two zero bytes.
> > 
> > > now i need to be able to extract the data back
> out
> > of
> > > the blob with sqlite3_column_blob and
> > > sqlite3_column_bytes so that i can repopulate an
> > > unsigned short array.
> > >
> > > if i have multiple blobs in the table Images how
> > would
> > > i go about retrieving back all this information?
> > 
> > You prepare a select statement, e.g.
> > 
> > select imageID, imageData from Images;
> > 
> > Then you loop over all rows in the resultset with
> > sqlite3_step call 
> > (each call advances to the next row), and for each
> > row call 
> > sqlite3_column_* once for each column you are
> > interested in.
> > 
> > Igor Tandetnik 
> > 
> > 
> > 
> > ___
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> >
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> > 
> 
> 
> 
>  
>

> Never miss a thing.  Make Yahoo your home page. 
> http://www.yahoo.com/r/hs
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Igor,

  thanks for all your help too man. here is what is in
the table images so far when i do a select. its 3
blobs:

sqlite> select imageID, hex(imageData) from Images;
1|00 0003 0006 0009 000C 000F 0012 0015 0018 001B 00
2|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
3|00 0001 0002 0003 0004 0005 0006 0007 0008 0009 00
*

here is what i have now:

const unsigned short *image;
int i = 0;

myString2 = "select imageID, imageData from Images";

int status = sqlite3_prepare_v2(db, update.c_str(),
-1, , NULL);

 while ((status = sqlite3_step(statement)) ==
SQLITE_ROW)
   {
i++

if(i == 1)
  std::cout << "first row" << std::endl;

else std::cout << "another row" << std::endl;

num_bytes = sqlite3_column_bytes(statement, i);
num_bytes = num_bytes / sizeof(unsigned short);
image = new unsigned short[num_bytes];
image = (const unsigned
short*)sqlite3_column_blob(statement, i);

for(int i = 0; i < num_bytes; i++)
   std::cout << "image " << i << ": " << image[i]
<< std::endl;

//delete [] image; //causes a crash so far. 
   }

 status = sqlite3_finalize(statement);
 if (status != SQLITE_OK)
 std::cerr << "Error deleting prepared SQL
statement" << std::endl;

 else std::cout << "finalized statement successfully"
<< std::endl;

***

Output:

first row
image 0: 0
image 1: 3
image 2: 6
image 3: 9
image 4: 12
image 5: 15
image 6: 18
image 7: 21
image 8: 24
image 9: 27
another row
another row
finalized statement successfully

--so for some reason i get the first
blob(successfully, yes!) but it never increments after
that. the statement is also finalized successfully.
any reason why the other two blobs are not printing
out? 

as a side note i commented out the deleting of the
image because i got a major abort crash, no doubt
memory leaks/forbidden access issues. 

thanks!! 






--- Igor Tandetnik <[EMAIL PROTECTED]> wrote:

> C S <[EMAIL PROTECTED]> wrote:
> >  thanks for the tip on the hex. now i can see my
> > entry of the blob. my original loop to fill the
> > dynamic array with unsigned shorts was this:
> >
> > imageArray = new unsigned short[10];
> >
> > for(int i = 0; i < 10; i++)
> >  imageArray[i] = i;
> >
> > so now if i run the program then do a:
> >
> > select imageID, hex(imageData) from Images;
> >
> > i get the result:
> >
> > 1|010002000300040005000600070008000900
> >
> > i am not sure where the first 2 leading zeros are
> > coming from
> 
> The first value (the one at index 0) in imageArray
> is zero, represented 
> by two zero bytes.
> 
> > now i need to be able to extract the data back out
> of
> > the blob with sqlite3_column_blob and
> > sqlite3_column_bytes so that i can repopulate an
> > unsigned short array.
> >
> > if i have multiple blobs in the table Images how
> would
> > i go about retrieving back all this information?
> 
> You prepare a select statement, e.g.
> 
> select imageID, imageData from Images;
> 
> Then you loop over all rows in the resultset with
> sqlite3_step call 
> (each call advances to the next row), and for each
> row call 
> sqlite3_column_* once for each column you are
> interested in.
> 
> Igor Tandetnik 
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Dennis,
  thanks for the tip on the hex. now i can see my
entry of the blob. my original loop to fill the
dynamic array with unsigned shorts was this:

imageArray = new unsigned short[10];

for(int i = 0; i < 10; i++)
  imageArray[i] = i;

so now if i run the program then do a:

select imageID, hex(imageData) from Images;

i get the result:

1|010002000300040005000600070008000900

i am not sure where the first 2 leading zeros are
coming from but that looks to be ok. 

now i need to be able to extract the data back out of
the blob with sqlite3_column_blob and
sqlite3_column_bytes so that i can repopulate an
unsigned short array. 

if i have multiple blobs in the table Images how would
i go about retrieving back all this information? 

somehow though i would think that i would need the
number of blob entries in the database to make this
work. 

for(int i = 0; i < blob_entries; i++)
 {
  numBytes = sqlite3_column_bytes(statement, i);
  sqlite3_column_blob(statement, i);
 }

--what do you think? thanks all for the help. its
appreciated. 

--- Dennis Cote <[EMAIL PROTECTED]> wrote:

> C S wrote:
> > 
> > i get nothing. i have a printout statement to make
> > sure an imageID was created and it was
> successfully.
> > the array is indeed dynamic and has to be. to echo
> > this is what i have:
> > 
> > myString = "insert into Images(imageID, imageData)
> > values(?, ?);
> > 
> > status = sqlite3_prepare_v2(db, myString.c_str(),
> -1,
> > , NULL);
> > 
> > void *blob = reinterpretcast(imageArray);
> > 
> 
> This should be:
> 
> void *blob = reinterpretcast(imageArray);
> 
> > status = sqlite3_bind_blob(statement, 2, blob, 10
> *
> > sizeof(unsigned short), SQLITE_STATIC);
> > 
> > statusu = sqlite3_finalize(statement);
> > 
> 
> You need to execute the insert statement before you
> finalize it. You 
> have created and destroyed the statement, but have
> not executed it. Add 
> the following between the two statements above:
> 
> status = sqlite3_step(statement);
> if (status != SQLITE_OK) {
>  //process error
> }
> 
> 
> > 
> > however when i do:
> > 
> > select * from Images;
> > 
> 
> To dump the blob data in a human readable format you
> could use the hex() 
> SQL function. It will display each byte of the blob
> as two ASCII 
> characters that correspond to the hexadecimal value
> of the byte.
> 
> select imageID, hex(imageData) from Images;
> 
> HTH
> Dennis Cote
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

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


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
replying to my own message - i added the step function
that i needed...so:

sqlite_step(statement), in between the bind and
finalize..

i deleted all the entries from the table so i could
start over, so when i do a select on Images i get:

1|

so either somehow i cant see the contents of the blob
or there is nothing there at all.

any suggestions?

 
--- C S <[EMAIL PROTECTED]> wrote:

> Dennis mentioned before that it was not necessary to
> do a bind on something that was defined as an
> integer
> primary key. 
> 
> when i do:
> 
> select * from Images;
> 
> 1|
> 2|
> 
> thats pretty much it. there are two entries because
> i
> tried to pure void cast as the previous message
> suggest vs the char * way..and it "seems" to make no
> difference. 
> 
> if i am supposed to bind the imageID what would that
> bind look like? which bind statement am i looking
> for?
> thanks!!
> --- "Matthew L. Creech" <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Mar 12, 2008 at 9:37 AM, C S
> > <[EMAIL PROTECTED]> wrote:
> > >
> > >  myString = "insert into Images(imageID,
> > imageData)
> > >  values(?, ?);
> > >
> > >
> > >  status = sqlite3_prepare_v2(db,
> myString.c_str(),
> > -1,
> > >  , NULL);
> > >
> > >  void *blob = reinterpretcast *>(imageArray);
> > >
> > >
> > >  status = sqlite3_bind_blob(statement, 2, blob,
> 10
> > *
> > >  sizeof(unsigned short), SQLITE_STATIC);
> > >
> > >  statusu = sqlite3_finalize(statement);
> > >
> > >  return sqlite3_last_insert_row(db);
> > >
> > >  
> > >
> > >  however when i do:
> > >
> > >  select * from Images;
> > >
> > >  i get no results returned to me. i just get
> > returned
> > >  to the prompt. is there anything that i missed?
> > thanks
> > >  again!!!
> > >
> > 
> > You're missing a bind for the first column (the
> > imageID), and more
> > importantly, a call to sqlite3_step() - you do
> need
> > one, otherwise the
> > insert never executes.  :)
> > 
> > -- 
> > Matthew L. Creech
> > ___
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> >
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> > 
> 
> 
> 
>  
>

> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now. 
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

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


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Dennis mentioned before that it was not necessary to
do a bind on something that was defined as an integer
primary key. 

when i do:

select * from Images;

1|
2|

thats pretty much it. there are two entries because i
tried to pure void cast as the previous message
suggest vs the char * way..and it "seems" to make no
difference. 

if i am supposed to bind the imageID what would that
bind look like? which bind statement am i looking for?
thanks!!
--- "Matthew L. Creech" <[EMAIL PROTECTED]> wrote:

> On Wed, Mar 12, 2008 at 9:37 AM, C S
> <[EMAIL PROTECTED]> wrote:
> >
> >  myString = "insert into Images(imageID,
> imageData)
> >  values(?, ?);
> >
> >
> >  status = sqlite3_prepare_v2(db, myString.c_str(),
> -1,
> >  , NULL);
> >
> >  void *blob = reinterpretcast(imageArray);
> >
> >
> >  status = sqlite3_bind_blob(statement, 2, blob, 10
> *
> >  sizeof(unsigned short), SQLITE_STATIC);
> >
> >  statusu = sqlite3_finalize(statement);
> >
> >  return sqlite3_last_insert_row(db);
> >
> >  
> >
> >  however when i do:
> >
> >  select * from Images;
> >
> >  i get no results returned to me. i just get
> returned
> >  to the prompt. is there anything that i missed?
> thanks
> >  again!!!
> >
> 
> You're missing a bind for the first column (the
> imageID), and more
> importantly, a call to sqlite3_step() - you do need
> one, otherwise the
> insert never executes.  :)
> 
> -- 
> Matthew L. Creech
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

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


Re: [sqlite] SQL Blobs - what am i doing wrong here?(code inside)

2008-03-12 Thread C S
Dennis,

   thanks for your and everyone elses help with this
problem. i actually did everything you said here and
the program executed without any errors. 

i re-created the table to what you said as now so it
is blob now instead of text. 

i get nothing. i have a printout statement to make
sure an imageID was created and it was successfully.
the array is indeed dynamic and has to be. to echo
this is what i have:

myString = "insert into Images(imageID, imageData)
values(?, ?);

status = sqlite3_prepare_v2(db, myString.c_str(), -1,
, NULL);

void *blob = reinterpretcast(imageArray);

status = sqlite3_bind_blob(statement, 2, blob, 10 *
sizeof(unsigned short), SQLITE_STATIC);

statusu = sqlite3_finalize(statement);

return sqlite3_last_insert_row(db);



however when i do:

select * from Images;

i get no results returned to me. i just get returned
to the prompt. is there anything that i missed? thanks
again!!!


--- Dennis Cote <[EMAIL PROTECTED]> wrote:

> C S wrote:
> > hi all - i am trying once again to insert an
> image(an
> > array of shorts) into a blob. 
> > 
> > i created a table that is described as such:
> > 
> > CREATE TABLE Images{
> > imageID integer primary key,
> > imageData text not null);
> > 
> > #1 - is text ok here for a blob? maybe not - this
> may
> > be my entire problem. 
> > 
> 
> I would recommend using a column type of BLOB for
> blob data just to 
> avoid any confusion.
> 
> CREATE TABLE Images (
>  imageID integer primary key,
>  imageData blob not null);
> 
> 
> > anyway instead of using data in an image i just
> made
> > an array of unsigned shorts and filled it. a size
> of
> > 10. 
> > 
> > so here is what i am doing in the code. imageArray
> > holds the unsigned shorts(there are 10 of them)
> > 
> > char* blob = reinterpret_cast<char*>(imageArray);
> > 
> 
> Generally you should use a void* instead of a char*
> for blobs.
> 
> void* blob = reinterpret_cast<void*>(imageArray);
> 
> This pointer isn't needed if your imageArray is a
> true array of unsigned 
> shorts rather than a pointer to some dynamically
> allocated memory.
> 
> unsigned short imageArray[10] =
> {1,2,3,4,5,6,7,8,9,10};
> 
> 
> > string myString = "insert into Images(ImageID,
> > imageData) values(?, 'blob')";
> 
> Note, this 'blob' is a string literal and has no
> relation at all to the 
> blob variable you defined above. You need to use a ?
> for the second 
> parameter as well so that you can bind a value to it
> later.
> 
> string myString = "insert into Images(ImageID,
> imageData) values(?, ?)";
> 
> > 
> > //then i want to try to prepare the statement:
> > 
> > int status = sqlite3_prepare_v2(db,
> myString.c_str(),
> > -1, , NULL);
> > if( (status != SQLITE_OK) || (statement == NULL))
> >   cout << "Error preparing SQL Statement" << endl;
> > 
> 
> There is no need to check statement here. SQLite
> will return an error 
> code other than SQLITE_OK if it fails.
> 
> > 
> > //now i would like to bind the blob:
> > 
> > status = sqlite3_bind_blob(statement, 1,
> imageArray,
> > 10 * sizeof(unsigned short), SQLITE_TRANSIENT);
> > 
> 
> The blob will be the second parameter to the
> statement. This parameter 
> can be static as long as the image data will be
> stable until the 
> statement is executed by sqlite3_step().
> 
> If you want to use the blob pointer above you should
> do this:
> 
> status = sqlite3_bind_blob(statement, 2, blob,
>  10 * sizeof(unsigned short), SQLITE_STATIC);
> 
> If imageArray is a true array as shown above you can
> instead do this:
> 
> status = sqlite3_bind_blob(statement, 2, imageArray,
>  sizeof(imageArray), SQLITE_STATIC);
> 
> You have not bound a value to the first parameter,
> the imageId column, 
> so it will have a null value when the statement
> executes. This is OK 
> since the column is declared as "integer primary
> key" and SQLite will 
> assign a unique ID value.
> 
> > 
> > //execute statement for each row??
> > while( (status = sqlite3_step(statement)) ==
> > SQLITE_ROW);
> > 
> 
> There is no need for a while loop here. An insert
> statement can only 
> step once, and sqlite3_step() will return
> SQLITE_DONE or some other 
> error code.
> 
> > //free the prepared statement
> > status = sqlite3_finalize(statement);
> > if(status != SQLITE_OK)
> >   cout << "Error deleting prepared SQL statement"
> <<

Re: [sqlite] using SQLite for binding blobs.

2008-02-15 Thread C S
sorry that should have been insert not insert2, sorry
for the confusion.

what do you mean no parameters in SQL? 

again sorry for sounding noobish -- well fact of the
matter is i am. ive learned as much as i have in  2
days so thanks for the patience and the string
suggestion. 

--- Igor Tandetnik <[EMAIL PROTECTED]> wrote:

> "C S" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > insert << "insert into Images values(NULL, '" <<
> Hello
> > World << "')"
> 
> As predicted, you don't have any parameters in your
> SQL, so there's 
> nothing to bind. It's also not clear why you use a
> stream. You probably 
> want something like
> 
> string insert =
> "insert into Images(imageID, messageID) values
> (?, 'Hello World');";
> 
> Question mark '?' is the parameter placeholder.
> 
> > long ID = db.performUpdate(insert2.str(),
> blobarray,
> > 10);
> 
> What's the relationship between variables named
> 'insert' and 'insert2'? 
> You initialize one, but then use the other.
> 
> Igor Tandetnik 
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] using SQLite for binding blobs.

2008-02-15 Thread C S
Ken,

  thanks for your response. for cross platform, both
windows and linux are little endian and Macs now use
intel chips, so that is not an issue. i was just
making sure everyone knew i wasnt just developing for
windows. 

about storing them as shorts -- i was under the
impression(at first) that sqlite wanted then data as
bytes but in my code that i just sent, i changed it
via a suggestion from Fin Springs(thanks again). 

please take a look at my code and tell me what is
wrong. i just got thrown into this sql stuff and
trying to learn it on the fly here. much appreciated. 


--- Ken <[EMAIL PROTECTED]> wrote:

> In addition to what Igor mentions:
> 
> If you want this array to be cross platform portable
> from Big endian to Little endian you either need to
> store some type of endianness flag.
> 
> If you dig into the sqlite source you'll find a
> function like sqlite3_put_varint.
> 
> It will convert 32 bit or 64 bit unsinged integers
> into a portable byte string.
> returning the number of bytes back that the string
> consumes. 
> You could then create a struct/type as follows
> struct {
> uint8_t  bytes;
> uint8_t  buf[3];
> }  vint;
> 
> vint.bytes = sqlite3_put_varint (, 
> yourShort );
> 
> then write the entire vint to the BLOB...
> 
> Retrieve the blob as normal. Then unload the shorts
> use the invers function.
> 
> But this seems like a lot of extra work to me.
> 
> Why not create a table that has the integer value
> and insert the data? One row per array element 
> 
> HTH
> 
> C S <[EMAIL PROTECTED]> wrote: hi all i have a
> question regarding Blobs, that is
> storing images into the database. 
> 
> my image by default is an unsigned short array and
> to
> bind blobs it wants a byte array. i am not sure i am
> doing this right at all. is there a universal cross
> platform way for this easy conversion? 
> 
> so far the code i have is:
> .
> char *byteArray = (char *) malloc((size * 2) *
> sizeof(char));
> .
> 
> for(unsigned int i = 0; i < index < size; i++)
> {
>  byteArray[2 * index] = (char)buffer[index];
>  byteArray[(2 * index) + 1] = ( (char) buffer[index]
> >> 1);
> 
> then i prepare the statement which is successful
> then:
> 
> status = sqlite3_bind_blob(statement, 1, byteArray,
> size * 2, free);
> 
> some questions i have: i get an error of '25' back
> from status and looking on the sqlite documention it
> says the 2nd parameter to sql bind was out of range.
> i
> have no idea how the 2nd parameter can be out of
> range. 
> 
> my next question is once you have the blob in the
> database how in the world do you read it back out?
> of
> course when i do read it back out i will need to
> convert it back to a short array to be able to use
> it.
> 
> 
> i am using C++(g++ compiler) on linux. thanks in
> advance! 
> 
> 
>  
>

> Never miss a thing.  Make Yahoo your home page. 
> http://www.yahoo.com/r/hs
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] using SQLite for binding blobs.

2008-02-15 Thread C S
this is to all who have responded so far: thanks so
much for your help so far: as a caveat, i am new to
SQL so bear with me..

here is my code from the main.cpp where i build the
short array: 

ostringstream insert;

unsigned short *blobarray = new unsigned short[10];

//for simple purposes i will make this a small array. 
for(int i = 0; i < 10; i++)
  blobArray[i] = i * 3;

insert << "insert into Images values(NULL, '" << Hello
World << "')"

long ID = db.performUpdate(insert2.str(), blobarray,
10);

...outside of main.

long performUpdate(string update, const unsigned short
* buffer, unsigned long size)
{
  sqlite3_stmt *statement;
  open(filename); //this simply opens the db file,
nothing big
  
  int status = sqlite3_prepare_v2(db, update.c_str(),
-1, , NULL);

  if((status != SQLITE_OK) || (statement == NULL))
cout << "error preparing" << endl;
  else cout << "preparing SQL statement successful" <<
endl;

  status = sqlite3_bind_blob(statement, 1, buffer,
size * sizeof(unsigned short), SQLITE_STATIC);

  if(status != SQLITE_OK)
cout << "status: " << status << " error binding
blob. " << endl;
  else cout << "binding blob successful" << endl;


  while((status = sqlite3_step(statement)) ==
SQLITE_ROW);
  //check for status error like above

  status = sqlite3_finalize(statement);
  //check for status error like above

//  other non sqlite stuff..

} //end performUpdate


do i need to create a column in table Images for the
blob? or does this happen automatically? right now i
have:

create tables Images(ImageID integer primary key,
 messageID text not null);

do i have to anything here for the blob?

i might have to come back to understand more about the
casting but right now i just wanted to show you my
code. i hope it is readable and once again thanks for
your help in advance! 





--- Fin Springs <[EMAIL PROTECTED]> wrote:

> 
> On Feb 15, 2008, at 5:40 PM, C S usmsci-at-yahoo.com
> |sqlite| wrote:
> 
> > hi all i have a question regarding Blobs, that is
> > storing images into the database.
> >
> > my image by default is an unsigned short array and
> to
> > bind blobs it wants a byte array. i am not sure i
> am
> > doing this right at all. is there a universal
> cross
> > platform way for this easy conversion?
> >
> > so far the code i have is:
> > .
> > char *byteArray = (char *) malloc((size * 2) *
> > sizeof(char));
> > .
> >
> > for(unsigned int i = 0; i < index < size; i++)
> > {
> > byteArray[2 * index] = (char)buffer[index];
> > byteArray[(2 * index) + 1] = ( (char)
> buffer[index]
> >>> 1);
> >
> There is probably no reason to copy your data into a
> separate char  
> array. Presuming you have something like:
> 
> unsigned short myImage[];
> size_t size; // the number of elements in your
> myImage array
> 
> - you can just do:
> 
> status = sqlite3_bind_blob(statement, 1, myImage,
> size *  
> sizeof(unsigned short), SQLITE_STATIC or
> SQLITE_TRANSIENT)
> 
> Your choice for the last parameter will depend on
> the life time of  
> 'myImage'; see
> http://sqlite.org/c3ref/bind_blob.html
> 
> > then i prepare the statement which is successful
> then:
> >
> > status = sqlite3_bind_blob(statement, 1,
> byteArray,
> > size * 2, free);
> >
> > some questions i have: i get an error of '25' back
> > from status and looking on the sqlite documention
> it
> > says the 2nd parameter to sql bind was out of
> range. i
> > have no idea how the 2nd parameter can be out of
> > range.
> You would need to share your statement definition.
> Is there at least  
> one '?' token in it?
> >
> >
> > my next question is once you have the blob in the
> > database how in the world do you read it back out?
> of
> > course when i do read it back out i will need to
> > convert it back to a short array to be able to use
> it.
> >
> Use sqlite3_column_blob to get the pointer and
> sqlite3_column_bytes to  
> know how much data there is (in bytes). You can just
> cast the 'const  
> void *' pointer that you get back to a 'const
> unsigned short *' and  
> divide the number of bytes there is by
> sizeof(unsigned short) (ie 2)  
> to get the number of elements.
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
>
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] using SQLite for binding blobs.

2008-02-15 Thread C S
hi all i have a question regarding Blobs, that is
storing images into the database. 

my image by default is an unsigned short array and to
bind blobs it wants a byte array. i am not sure i am
doing this right at all. is there a universal cross
platform way for this easy conversion? 

so far the code i have is:
.
char *byteArray = (char *) malloc((size * 2) *
sizeof(char));
.

for(unsigned int i = 0; i < index < size; i++)
{
 byteArray[2 * index] = (char)buffer[index];
 byteArray[(2 * index) + 1] = ( (char) buffer[index]
>> 1);

then i prepare the statement which is successful then:

status = sqlite3_bind_blob(statement, 1, byteArray,
size * 2, free);

some questions i have: i get an error of '25' back
from status and looking on the sqlite documention it
says the 2nd parameter to sql bind was out of range. i
have no idea how the 2nd parameter can be out of
range. 

my next question is once you have the blob in the
database how in the world do you read it back out? of
course when i do read it back out i will need to
convert it back to a short array to be able to use it.


i am using C++(g++ compiler) on linux. thanks in
advance! 


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users