Re: [sqlite] sqlite3_stat problem (YAN HONG YE)

2012-08-02 Thread Rob Richardson
OK for now, but for how long?  I still think that 140 is going to come back and 
bite you in the rear end sometime when you're not expecting it.  As I 
understand it, you have a short collection of bytes that is the result of 
encrypting a short string.  You have much less than 140 bytes of data to store. 
 You are storing four bytes (or whatever) of encrypted data, followed by 136 
bytes of random crud.  When it finally comes time to extract the encrypted data 
from the database and unencrypt it, your unencryption algorithm isn't going to 
know what to with those extra 136 bytes, and you'll get junk.

And as I said in my last message, NULL is not a valid choice for the fifth 
argument.  The fact that it works does not change the fact that it is not 
valid.  Please choose an appropriate value as listed in the documentation for 
that parameter.

Always write code as though the next person to look at it just graduated from 
college and never wrote a line of professional code in his life.  For one 
thing, you may come back to it in two years and ask yourself, "Why the heck did 
I do THAT?"

RobR


-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of YAN HONG YE
Sent: Thursday, August 02, 2012 3:20 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] sqlite3_stat problem (YAN HONG YE)

sqlite3_bind_text(stat,1,uu2,140,NULL); 
change to 
sqlite3_bind_blob(stat,1,uu2,140,NULL);
it's ok! thank you!
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] sqlite3_stat problem (YAN HONG YE)

2012-08-02 Thread YAN HONG YE
sqlite3_bind_text(stat,1,uu2,140,NULL); 
change to 
sqlite3_bind_blob(stat,1,uu2,140,NULL);
it's ok! thank you!
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] sqlite3_stat problem

2012-08-01 Thread Rob Richardson
Return values are your friends.  Use them.  Store the error code from every 
sqlite function call, and if the error code is not SQLITE_OK (NOTE:  Check that 
that is the correct name.), then display what the error code is.  In 
particular, what is the return value of your sqlite3_bind_text() function call?

If the documentation of a function states that a parameter requires a named 
special value, use that name.  The fifth argument should be a destructor 
function pointer, SQLITE_STATIC or SQLITE_TRANSIENT.  Read the documentation to 
understand what each one means.

Learn to cringe every time you put a constant value into your code.  People 
often call hard-coded constants "magic numbers" because they apparently showed 
up magically, since there's no other explanation of where they came from.  
Where did "140" come from?  Why do you need it?  The parameter requires the 
length of a string.  So use strlen() (again, check the correctness.  It's been 
so long since I've used these functions, the name could be wrong) to calculate 
the actual length of the string.  The documentation states that if the fourth 
argument is not negative, it is the byte offset where the null terminator 
should be, and any null terminators before that are included in the bound 
string, and if any null terminators are included in the bound string, behavior 
is undefined.  That's exactly the situation you have.  

And when you use strlen() or whatever you use to calculate the length of the 
string, be careful to take into account the difference between bytes and 
characters.  The sqlite3_bind_text() call requires bytes, but your characters 
may be one or two bytes.

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


Re: [sqlite] sqlite3_stat problem

2012-07-31 Thread Keith Medcalf
 
>>  sqlite3_bind_text(stat,1,uu2,140,NULL);

> uu2 is 4 bytes, not 140; are you sure that it is valid UTF-8 text and not a
> blob-o-bytes?

It may also be SQLITE_TRANSIENT rather than SQLITE_STATIC ...

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org



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


Re: [sqlite] sqlite3_stat problem

2012-07-31 Thread Keith Medcalf

>   sqlite3_bind_text(stat,1,uu2,140,NULL);

uu2 is 4 bytes, not 140; are you sure that it is valid UTF-8 text and not a 
blob-o-bytes?

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org

> -Original Message-
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of YAN HONG YE
> Sent: Tuesday, 31 July, 2012 19:30
> To: sqlite-users@sqlite.org
> Subject: [sqlite] sqlite3_stat problem
> 
> sprintf(sql,"insert into student select 1,?,22;");
> 
> 
>   sqlite3_prepare(l_db,sql,-1,,0);
>   char *uu1="bb";
>   char *uu2="Öйú";
> 
> 
>   HINSTANCE mod;
>   Connect foo;
>   mod = LoadLibrary("crypto.dll");
>   printf("1successful load dll1\n");
>   printf("2successful load dll2\n");
>   printf("3successful load dll3\n");
>   printf("4successful load dll4\n");
>   if((foo = (Connect)GetProcAddress(mod, "CryptMe")) != NULL)
>   {
>   printf("5successful load dll5\n");
>   foo(uu1,uu2,1);   //here to 
> encode
> the uu2 to " Íð¦·"
>   }
> 
> 
>   printf("%s\n",uu2);   //the result:" Íð¦·"
> 
>   printf("7successful load dll7\n");
>   sqlite3_bind_text(stat,1,uu2,140,NULL);
>   printf("8successful load dll8\n");
>   sqlite3_step(stat);
>   printf("9successful load dll9\n"); //here not
> print, shou the error msg:  jii.exe has encountered a problem and needs to
>   //close.  We are sorry for 
> the
> inconvenience.
>   sqlite3_finalize(stat);
>   printf("10successful load dll10\n");
> ___
> 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


[sqlite] sqlite3_stat problem

2012-07-31 Thread YAN HONG YE
sprintf(sql,"insert into student select 1,?,22;");


sqlite3_prepare(l_db,sql,-1,,0);
char *uu1="bb";
char *uu2="Öйú";


HINSTANCE mod; 
Connect foo;
mod = LoadLibrary("crypto.dll");
printf("1successful load dll1\n");
printf("2successful load dll2\n");
printf("3successful load dll3\n");
printf("4successful load dll4\n");
if((foo = (Connect)GetProcAddress(mod, "CryptMe")) != NULL) 
{
printf("5successful load dll5\n");
foo(uu1,uu2,1);   //here to 
encode the uu2 to " Íð¦·"
}


printf("%s\n",uu2);   //the result:" Íð¦·"

printf("7successful load dll7\n");
sqlite3_bind_text(stat,1,uu2,140,NULL);
printf("8successful load dll8\n");
sqlite3_step(stat);
printf("9successful load dll9\n"); //here not 
print, shou the error msg:  jii.exe has encountered a problem and needs to  
  //close.  We are sorry 
for the inconvenience.
sqlite3_finalize(stat);
printf("10successful load dll10\n");
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users