RE: [sqlite] starting with unicode

2006-08-16 Thread Rob Richardson
No, you don't need sqlite3_reset() inside the loop.  The pseudocode
should be:

open
prepare
loop while not at end of file
step
read
repeat
finalize
close

For the "read" portion, use the sqlite_column_xxx() methods.  

And wrap every single string in your code in the _T() macro, or you'll
get errors everywhere when you finally move to a Unicode build.

RobR

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-15 Thread Nikki Locke
Mark Wyszomierski wrote:
> Why do we want to use sqlite3_reset() in the for loop? If I leave it 
> in, the loop keeps running forever since I guess it really does keep 
> resetting the sql statement. Do we need it though inside the while 
> loop when SQLITE_BUSY is returned though? Is that the proper way to 
> try again after being busy, or will it again reset the entire 
> statement and throw back to an infiinite loop? 

Perhaps you don't - I was just correcting the glaring mistakes in your code, so 
it 
more closely resembled the pseudo-code it was supposed to be based on. So far I 
have only used SQLite from C#, so I don't get involved in all that stuff.

-- 
Nikki Locke, Trumphurst Ltd.  PC & Unix consultancy & programming
http://www.trumphurst.com/



-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-15 Thread John Stanton
If you have no variables in your SQL (like SELECT * FROM ...) then you 
don't bind.


If you have "SELECT * FROM junk WHERE name=?" then you need to bind like 
this.  The bind is good until you do a reset.


char that_name = "Harry";
...
rc = sqlite3_bind_text(xek, 1, that_name, -1, SQLITE_STATIC);
if (rc == SQLITE_OK) return(FALSE);

/*Could return with an error, but have errcode OK.*/
err = sqlite3_errcode(db);
if (err != SQLITE_OK) {
  errormet("908", (char *)sqlite3_errmsg(db), (char *)fnm);  /*Fatal DB 
Error.*/

  return(TRUE);
}  /*if*/
return(FALSE);

Sqlite will see - SELECT * FROM junk WHERE name="Harry".

Mark Wyszomierski wrote:

I suppose this is correct:

strSql.Format(_T("SELECT * FROM test"));

char szSomething[500];
int nTest = sqlite3_bind_text(pStmt, 1, szSomething, 500, SQLITE_STATIC);
if (nTest != SQLITE_OK) {
   TRACE("sqlite3_bind_text fails!! [%i] [%s]\n", nTest, 
sqlite3_errmsg(db));

}

but can I use the string "SELECT * FROM test", if not how do I use
those question marks or AAA variable identifiers in the string itself
to achieve binding?

Thanks,
Mark

On 8/14/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:


John, Cory, thank you very much. I got execute plain statements ok by
modifying my earlier posting a bit. I was able to create a table using
the prepare statement.

Previously I was using sqlite3_exec() to execute my statements and I
could pass it a callback function which I could use to fetch data for
SELECT statements. How do we do that now with the prepare() and step()
statements? Just some pseudocode like before would be fine. Here in my
test table I have two dummy records and the while loop correctly
iterates over both of them - but how to get the values in each row?

   // Table test looks like:

   // something | something_else
   // --
   //   hello   |   there
   //   bye|   guy

   strSql.Format(_T("SELECT * FROM test"));

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   if (nRetVal != SQLITE_OK) {
   TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
   return false;
   }

   nRetVal = sqlite3_step(pStmt);
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);

   // How do I get the information out of this returned record?

   // By the way, why would we want a reset() in here?
 //  sqlite3_reset(pStmt);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);


Thanks,
Mark



On 8/14/06, John Stanton <[EMAIL PROTECTED]> wrote:
> Mark Wyszomierski wrote:
> > Hi Cory,
> >
> > Alright I gave it a shot from the docs but I'm not handling the
> > prepare statement correctly. I'm trying the ASCI version first. The
> > prepare statement returns an error. Here is the code snippet I'm
> > trying:
> >
> >
> > strSql.Format("CREATE TABLE test (something TEXT, something_else 
TEXT,

> > primary key(something))");
> >
> >sqlite3_stmt *pStmt;
> >const char *pszTailPointer;
> >int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
> > , );
> >while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
> >Sleep(100);
> >// Try again.
> >nRetVal = sqlite3_step(pStmt);
> >TRACE("ret val was [%i]\n", nRetVal);
> >}
> >switch (nRetVal) {
> >case SQLITE_DONE:
> >TRACE("Done ok\n");
> >break;
> >case SQLITE_ERROR:
> >TRACE("ERROR\n");
> >break;
> >case SQLITE_MISUSE:
> >TRACE("MISUSE\n");
> >break;
> >default:
> >break;
> >}
> >sqlite3_finalize(pStmt);
> >return true;
> >
> > Any hints?
> >
> > Thanks,
> > Mark
> >
> >
> > On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:
> >
> >> On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
> >> > Hi,
> >> >
> >> > I have been using sqlite on windows for a few months, it is 
great. I
> >> > need to switch over to unicode support now though, and I am 
confused

> >> > how to do this with sqlite.
> >> >
> >> > 1) First, when I compiled the original sqlite project, I have the
> >> > character set to MBCS. Should I switch this to Unicode and 
recompile?

> >>
> >> I think SQLite explicitly calls CreateFileW but I could be wrong.
> >> Might as well compile as Unicode anyway.
> >>
> >> > 2) I have been using sqlite3_exec() to execute my sql 
statements, but
> >> > I see that there is no sqlite3_exec16() equivalent to take a 
unicode
> >> > string. I think I'm supposed to use sqlite3_prepare16() but I 
have no

> >> > idea what the last 

Re: [sqlite] starting with unicode

2006-08-15 Thread John Stanton

Mark Wyszomierski wrote:

John, Cory, thank you very much. I got execute plain statements ok by
modifying my earlier posting a bit. I was able to create a table using
the prepare statement.

Previously I was using sqlite3_exec() to execute my statements and I
could pass it a callback function which I could use to fetch data for
SELECT statements. How do we do that now with the prepare() and step()
statements? Just some pseudocode like before would be fine. Here in my
test table I have two dummy records and the while loop correctly
iterates over both of them - but how to get the values in each row?

   // Table test looks like:

   // something | something_else
   // --
   //   hello   |   there
   //   bye|   guy

   strSql.Format(_T("SELECT * FROM test"));

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   if (nRetVal != SQLITE_OK) {
   TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
   return false;
   }

   nRetVal = sqlite3_step(pStmt);
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);

   // How do I get the information out of this returned record?

   // By the way, why would we want a reset() in here?
 //  sqlite3_reset(pStmt);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);


Thanks,
Mark



On 8/14/06, John Stanton <[EMAIL PROTECTED]> wrote:


Mark Wyszomierski wrote:
> Hi Cory,
>
> Alright I gave it a shot from the docs but I'm not handling the
> prepare statement correctly. I'm trying the ASCI version first. The
> prepare statement returns an error. Here is the code snippet I'm
> trying:
>
>
> strSql.Format("CREATE TABLE test (something TEXT, something_else TEXT,
> primary key(something))");
>
>sqlite3_stmt *pStmt;
>const char *pszTailPointer;
>int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
> , );
>while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
>Sleep(100);
>// Try again.
>nRetVal = sqlite3_step(pStmt);
>TRACE("ret val was [%i]\n", nRetVal);
>}
>switch (nRetVal) {
>case SQLITE_DONE:
>TRACE("Done ok\n");
>break;
>case SQLITE_ERROR:
>TRACE("ERROR\n");
>break;
>case SQLITE_MISUSE:
>TRACE("MISUSE\n");
>break;
>default:
>break;
>}
>sqlite3_finalize(pStmt);
>return true;
>
> Any hints?
>
> Thanks,
> Mark
>
>
> On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:
>
>> On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
>> > Hi,
>> >
>> > I have been using sqlite on windows for a few months, it is great. I
>> > need to switch over to unicode support now though, and I am confused
>> > how to do this with sqlite.
>> >
>> > 1) First, when I compiled the original sqlite project, I have the
>> > character set to MBCS. Should I switch this to Unicode and 
recompile?

>>
>> I think SQLite explicitly calls CreateFileW but I could be wrong.
>> Might as well compile as Unicode anyway.
>>
>> > 2) I have been using sqlite3_exec() to execute my sql statements, 
but

>> > I see that there is no sqlite3_exec16() equivalent to take a unicode
>> > string. I think I'm supposed to use sqlite3_prepare16() but I 
have no

>> > idea what the last two parameters of that function are?
>>
>> Check the docs, they explain how to use prepared statements.
>>
>> > 3) To escape my sql statements I was using sqlite3_mprintf() - is
>> > there a unicode equivalent?
>>
>> With prepared statements you put placeholders like "?" into your sql
>> and bind data to the placeholders - no escaping required.
>>
>> > Thanks for any information,
>> > Mark
>> >
>> >
>> 
- 


>>
>> > To unsubscribe, send email to [EMAIL PROTECTED]
>> >
>> 
- 


>>
>> >
>> >
>>
>>
>> --
>> Cory Nelson
>> http://www.int64.org
>>
>> 
- 


>>
>> To unsubscribe, send email to [EMAIL PROTECTED]
>> 
- 


>>
>>
>>
>
> 
- 


>
> To unsubscribe, send email to [EMAIL PROTECTED]
> 
- 


>
>
A "prepare" just compiles the statment, and does not get busy.  You do
it to get ready for your 

Re: [sqlite] starting with unicode

2006-08-15 Thread Mark Wyszomierski

Hi Nikki,

Why do we want to use sqlite3_reset() in the for loop? If I leave it
in, the loop keeps running forever since I guess it really does keep
resetting the sql statement. Do we need it though inside the while
loop when SQLITE_BUSY is returned though? Is that the proper way to
try again after being busy, or will it again reset the entire
statement and throw back to an infiinite loop?

Thanks,
Mark


On 8/15/06, Nikki Locke <[EMAIL PROTECTED]> wrote:

Mark Wyszomierski wrote:
>strSql.Format(_T("SELECT * FROM test"));
>
>sqlite3_stmt *pStmt;
>const char *pszTailPointer;
>int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
> , );
>if (nRetVal != SQLITE_OK) {
>TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
>return false;
>}
>
>nRetVal = sqlite3_step(pStmt);
>while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
>Sleep(100);
>// Try again.
>nRetVal = sqlite3_step(pStmt);
>// How do I get the information out of this returned record?
>
>// By the way, why would we want a reset() in here?
>  //  sqlite3_reset(pStmt);
>}

Your error checking is all wrong. Try something like this...

  int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(), ,
);
  if (nRetVal != SQLITE_OK) {
  TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
  return false;
  }

  for ( ; ; ) {
 while((nRetVal = sqlite3_step(pStmt)) == SQLITE_BUSY) {
Sleep(100);
sqlite3_reset(pStmt);  // Not sure if this is needed
 }
 if (nRetVal != SQLITE_ROW)
break; // No more rows, or an error
 // How do I get the information out of this returned record?

 sqlite3_reset(pStmt); // Ready for the next sqlite3_step
  }



--
Nikki Locke, Trumphurst Ltd.  PC & Unix consultancy & programming
http://www.trumphurst.com/



-
To unsubscribe, send email to [EMAIL PROTECTED]
-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-15 Thread Nikki Locke
Mark Wyszomierski wrote:
>strSql.Format(_T("SELECT * FROM test")); 
>  
>sqlite3_stmt *pStmt; 
>const char *pszTailPointer; 
>int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(), 
> , ); 
>if (nRetVal != SQLITE_OK) { 
>TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db)); 
>return false; 
>} 
>  
>nRetVal = sqlite3_step(pStmt); 
>while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) { 
>Sleep(100); 
>// Try again. 
>nRetVal = sqlite3_step(pStmt); 
>// How do I get the information out of this returned record? 
>  
>// By the way, why would we want a reset() in here? 
>  //  sqlite3_reset(pStmt); 
>} 

Your error checking is all wrong. Try something like this...

   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(), , 
); 
   if (nRetVal != SQLITE_OK) { 
   TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db)); 
   return false; 
   } 

   for ( ; ; ) {
  while((nRetVal = sqlite3_step(pStmt)) == SQLITE_BUSY) {
 Sleep(100);
 sqlite3_reset(pStmt);  // Not sure if this is needed
  }
  if (nRetVal != SQLITE_ROW)
 break; // No more rows, or an error
  // How do I get the information out of this returned record? 
 
  sqlite3_reset(pStmt); // Ready for the next sqlite3_step
   } 



-- 
Nikki Locke, Trumphurst Ltd.  PC & Unix consultancy & programming
http://www.trumphurst.com/



-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-14 Thread Mark Wyszomierski

I suppose this is correct:

strSql.Format(_T("SELECT * FROM test"));

char szSomething[500];
int nTest = sqlite3_bind_text(pStmt, 1, szSomething, 500, SQLITE_STATIC);
if (nTest != SQLITE_OK) {
   TRACE("sqlite3_bind_text fails!! [%i] [%s]\n", nTest, sqlite3_errmsg(db));
}

but can I use the string "SELECT * FROM test", if not how do I use
those question marks or AAA variable identifiers in the string itself
to achieve binding?

Thanks,
Mark

On 8/14/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:

John, Cory, thank you very much. I got execute plain statements ok by
modifying my earlier posting a bit. I was able to create a table using
the prepare statement.

Previously I was using sqlite3_exec() to execute my statements and I
could pass it a callback function which I could use to fetch data for
SELECT statements. How do we do that now with the prepare() and step()
statements? Just some pseudocode like before would be fine. Here in my
test table I have two dummy records and the while loop correctly
iterates over both of them - but how to get the values in each row?

   // Table test looks like:

   // something | something_else
   // --
   //   hello   |   there
   //   bye|   guy

   strSql.Format(_T("SELECT * FROM test"));

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   if (nRetVal != SQLITE_OK) {
   TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
   return false;
   }

   nRetVal = sqlite3_step(pStmt);
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);

   // How do I get the information out of this returned record?

   // By the way, why would we want a reset() in here?
 //  sqlite3_reset(pStmt);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);


Thanks,
Mark



On 8/14/06, John Stanton <[EMAIL PROTECTED]> wrote:
> Mark Wyszomierski wrote:
> > Hi Cory,
> >
> > Alright I gave it a shot from the docs but I'm not handling the
> > prepare statement correctly. I'm trying the ASCI version first. The
> > prepare statement returns an error. Here is the code snippet I'm
> > trying:
> >
> >
> > strSql.Format("CREATE TABLE test (something TEXT, something_else TEXT,
> > primary key(something))");
> >
> >sqlite3_stmt *pStmt;
> >const char *pszTailPointer;
> >int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
> > , );
> >while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
> >Sleep(100);
> >// Try again.
> >nRetVal = sqlite3_step(pStmt);
> >TRACE("ret val was [%i]\n", nRetVal);
> >}
> >switch (nRetVal) {
> >case SQLITE_DONE:
> >TRACE("Done ok\n");
> >break;
> >case SQLITE_ERROR:
> >TRACE("ERROR\n");
> >break;
> >case SQLITE_MISUSE:
> >TRACE("MISUSE\n");
> >break;
> >default:
> >break;
> >}
> >sqlite3_finalize(pStmt);
> >return true;
> >
> > Any hints?
> >
> > Thanks,
> > Mark
> >
> >
> > On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:
> >
> >> On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
> >> > Hi,
> >> >
> >> > I have been using sqlite on windows for a few months, it is great. I
> >> > need to switch over to unicode support now though, and I am confused
> >> > how to do this with sqlite.
> >> >
> >> > 1) First, when I compiled the original sqlite project, I have the
> >> > character set to MBCS. Should I switch this to Unicode and recompile?
> >>
> >> I think SQLite explicitly calls CreateFileW but I could be wrong.
> >> Might as well compile as Unicode anyway.
> >>
> >> > 2) I have been using sqlite3_exec() to execute my sql statements, but
> >> > I see that there is no sqlite3_exec16() equivalent to take a unicode
> >> > string. I think I'm supposed to use sqlite3_prepare16() but I have no
> >> > idea what the last two parameters of that function are?
> >>
> >> Check the docs, they explain how to use prepared statements.
> >>
> >> > 3) To escape my sql statements I was using sqlite3_mprintf() - is
> >> > there a unicode equivalent?
> >>
> >> With prepared statements you put placeholders like "?" into your sql
> >> and bind data to the placeholders - no escaping required.
> >>
> >> > Thanks for any information,
> >> > Mark
> >> >
> >> >
> >> 
-
> >>
> >> > To unsubscribe, send email to [EMAIL PROTECTED]
> >> >
> >> 
-

Re: [sqlite] starting with unicode

2006-08-14 Thread Mark Wyszomierski

John, Cory, thank you very much. I got execute plain statements ok by
modifying my earlier posting a bit. I was able to create a table using
the prepare statement.

Previously I was using sqlite3_exec() to execute my statements and I
could pass it a callback function which I could use to fetch data for
SELECT statements. How do we do that now with the prepare() and step()
statements? Just some pseudocode like before would be fine. Here in my
test table I have two dummy records and the while loop correctly
iterates over both of them - but how to get the values in each row?

   // Table test looks like:

   // something | something_else
   // --
   //   hello   |   there
   //   bye|   guy

   strSql.Format(_T("SELECT * FROM test"));

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   if (nRetVal != SQLITE_OK) {
   TRACE("prepare fails!! [%i] [%s]\n", nRetVal, sqlite3_errmsg(db));
   return false;
   }

   nRetVal = sqlite3_step(pStmt);
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);

   // How do I get the information out of this returned record?

   // By the way, why would we want a reset() in here?
 //  sqlite3_reset(pStmt);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);


Thanks,
Mark



On 8/14/06, John Stanton <[EMAIL PROTECTED]> wrote:

Mark Wyszomierski wrote:
> Hi Cory,
>
> Alright I gave it a shot from the docs but I'm not handling the
> prepare statement correctly. I'm trying the ASCI version first. The
> prepare statement returns an error. Here is the code snippet I'm
> trying:
>
>
> strSql.Format("CREATE TABLE test (something TEXT, something_else TEXT,
> primary key(something))");
>
>sqlite3_stmt *pStmt;
>const char *pszTailPointer;
>int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
> , );
>while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
>Sleep(100);
>// Try again.
>nRetVal = sqlite3_step(pStmt);
>TRACE("ret val was [%i]\n", nRetVal);
>}
>switch (nRetVal) {
>case SQLITE_DONE:
>TRACE("Done ok\n");
>break;
>case SQLITE_ERROR:
>TRACE("ERROR\n");
>break;
>case SQLITE_MISUSE:
>TRACE("MISUSE\n");
>break;
>default:
>break;
>}
>sqlite3_finalize(pStmt);
>return true;
>
> Any hints?
>
> Thanks,
> Mark
>
>
> On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:
>
>> On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
>> > Hi,
>> >
>> > I have been using sqlite on windows for a few months, it is great. I
>> > need to switch over to unicode support now though, and I am confused
>> > how to do this with sqlite.
>> >
>> > 1) First, when I compiled the original sqlite project, I have the
>> > character set to MBCS. Should I switch this to Unicode and recompile?
>>
>> I think SQLite explicitly calls CreateFileW but I could be wrong.
>> Might as well compile as Unicode anyway.
>>
>> > 2) I have been using sqlite3_exec() to execute my sql statements, but
>> > I see that there is no sqlite3_exec16() equivalent to take a unicode
>> > string. I think I'm supposed to use sqlite3_prepare16() but I have no
>> > idea what the last two parameters of that function are?
>>
>> Check the docs, they explain how to use prepared statements.
>>
>> > 3) To escape my sql statements I was using sqlite3_mprintf() - is
>> > there a unicode equivalent?
>>
>> With prepared statements you put placeholders like "?" into your sql
>> and bind data to the placeholders - no escaping required.
>>
>> > Thanks for any information,
>> > Mark
>> >
>> >
>> -
>>
>> > To unsubscribe, send email to [EMAIL PROTECTED]
>> >
>> -
>>
>> >
>> >
>>
>>
>> --
>> Cory Nelson
>> http://www.int64.org
>>
>> -
>>
>> To unsubscribe, send email to [EMAIL PROTECTED]
>> -
>>
>>
>>
>
> -
>
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
>
>
A "prepare" just compiles the statment, and does not get busy.  You do
it to get ready for your execution loop.

You execute the compiled statement with 

Re: [sqlite] starting with unicode

2006-08-14 Thread John Stanton

Mark Wyszomierski wrote:

Hi Cory,

Alright I gave it a shot from the docs but I'm not handling the
prepare statement correctly. I'm trying the ASCI version first. The
prepare statement returns an error. Here is the code snippet I'm
trying:


strSql.Format("CREATE TABLE test (something TEXT, something_else TEXT,
primary key(something))");

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);
   TRACE("ret val was [%i]\n", nRetVal);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);
   return true;

Any hints?

Thanks,
Mark


On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:


On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have been using sqlite on windows for a few months, it is great. I
> need to switch over to unicode support now though, and I am confused
> how to do this with sqlite.
>
> 1) First, when I compiled the original sqlite project, I have the
> character set to MBCS. Should I switch this to Unicode and recompile?

I think SQLite explicitly calls CreateFileW but I could be wrong.
Might as well compile as Unicode anyway.

> 2) I have been using sqlite3_exec() to execute my sql statements, but
> I see that there is no sqlite3_exec16() equivalent to take a unicode
> string. I think I'm supposed to use sqlite3_prepare16() but I have no
> idea what the last two parameters of that function are?

Check the docs, they explain how to use prepared statements.

> 3) To escape my sql statements I was using sqlite3_mprintf() - is
> there a unicode equivalent?

With prepared statements you put placeholders like "?" into your sql
and bind data to the placeholders - no escaping required.

> Thanks for any information,
> Mark
>
> 
- 


> To unsubscribe, send email to [EMAIL PROTECTED]
> 
- 


>
>


--
Cory Nelson
http://www.int64.org

- 


To unsubscribe, send email to [EMAIL PROTECTED]
- 






- 


To unsubscribe, send email to [EMAIL PROTECTED]
- 



A "prepare" just compiles the statment, and does not get busy.  You do 
it to get ready for your execution loop.


You execute the compiled statement with "step" and then call "reset" to 
check for errors and intialize the compiled statement ready for the next 
"step".  At the end of your processing you "finalize" the statement to 
tidy up and let you close the database.


   open
   prepare
   loop
   step
   reset
   repeat
   finalize
   close

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-14 Thread Mark Wyszomierski

Hi Cory,

Alright I gave it a shot from the docs but I'm not handling the
prepare statement correctly. I'm trying the ASCI version first. The
prepare statement returns an error. Here is the code snippet I'm
trying:


strSql.Format("CREATE TABLE test (something TEXT, something_else TEXT,
primary key(something))");

   sqlite3_stmt *pStmt;
   const char *pszTailPointer;
   int nRetVal = sqlite3_prepare(db, strSql, strSql.GetLength(),
, );
   while (nRetVal == SQLITE_BUSY || nRetVal == SQLITE_ROW) {
   Sleep(100);
   // Try again.
   nRetVal = sqlite3_step(pStmt);
   TRACE("ret val was [%i]\n", nRetVal);
   }
   switch (nRetVal) {
   case SQLITE_DONE:
   TRACE("Done ok\n");
   break;
   case SQLITE_ERROR:
   TRACE("ERROR\n");
   break;
   case SQLITE_MISUSE:
   TRACE("MISUSE\n");
   break;
   default:
   break;
   }
   sqlite3_finalize(pStmt);
   return true;

Any hints?

Thanks,
Mark


On 8/13/06, Cory Nelson <[EMAIL PROTECTED]> wrote:

On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have been using sqlite on windows for a few months, it is great. I
> need to switch over to unicode support now though, and I am confused
> how to do this with sqlite.
>
> 1) First, when I compiled the original sqlite project, I have the
> character set to MBCS. Should I switch this to Unicode and recompile?

I think SQLite explicitly calls CreateFileW but I could be wrong.
Might as well compile as Unicode anyway.

> 2) I have been using sqlite3_exec() to execute my sql statements, but
> I see that there is no sqlite3_exec16() equivalent to take a unicode
> string. I think I'm supposed to use sqlite3_prepare16() but I have no
> idea what the last two parameters of that function are?

Check the docs, they explain how to use prepared statements.

> 3) To escape my sql statements I was using sqlite3_mprintf() - is
> there a unicode equivalent?

With prepared statements you put placeholders like "?" into your sql
and bind data to the placeholders - no escaping required.

> Thanks for any information,
> Mark
>
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
>
>


--
Cory Nelson
http://www.int64.org

-
To unsubscribe, send email to [EMAIL PROTECTED]
-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] starting with unicode

2006-08-13 Thread Cory Nelson

On 8/13/06, Mark Wyszomierski <[EMAIL PROTECTED]> wrote:

Hi,

I have been using sqlite on windows for a few months, it is great. I
need to switch over to unicode support now though, and I am confused
how to do this with sqlite.

1) First, when I compiled the original sqlite project, I have the
character set to MBCS. Should I switch this to Unicode and recompile?


I think SQLite explicitly calls CreateFileW but I could be wrong.
Might as well compile as Unicode anyway.


2) I have been using sqlite3_exec() to execute my sql statements, but
I see that there is no sqlite3_exec16() equivalent to take a unicode
string. I think I'm supposed to use sqlite3_prepare16() but I have no
idea what the last two parameters of that function are?


Check the docs, they explain how to use prepared statements.


3) To escape my sql statements I was using sqlite3_mprintf() - is
there a unicode equivalent?


With prepared statements you put placeholders like "?" into your sql
and bind data to the placeholders - no escaping required.


Thanks for any information,
Mark

-
To unsubscribe, send email to [EMAIL PROTECTED]
-





--
Cory Nelson
http://www.int64.org

-
To unsubscribe, send email to [EMAIL PROTECTED]
-