At 9:02 PM -0600 1/5/04, Nate Bargmann wrote:
>I'm working with SQLite through a Perl script to store some data files
>on CD-ROM into tables.  Everything has gone rather well considering I am
>learning SQL and SQLite as I go along.  The data files are CSV and
>appear to be an SQL variant used by a proprietary SQL engine installed
>by the CD's setup program on another OS.
>Anyway, I am seeing the following behavior--when the following line is
>put into the database with an INSERT command:
>"How Do You Like Our QST, OM?", ...
>SQLite gives me this
>'How Do You Like Our QST, OMNULL', ...
>Yet, a '?' inside a string followed by a space passed into the column
>data just fine.
<snip>

The "problem" you are having is specific to Perl/DBI and not to SQLite. 

Having a bareword "?" in a SQL string is something special to DBI; it is a variable 
binding operator and will be replaced with the contents of the Perl variable that you 
pick.  SQLite only sees the resulting SQL string after this substitution has taken 
place.  If no associated variable is provided, then NULL is used (although my version 
throws an exception instead, though that's probably because I 'use strict' and 'use 
warnings', as every Perl user should do).  Inside a string, the '?' is taken as a 
literal character.

Have a look here for a proper explanation:

http://search.cpan.org/dist/DBI/DBI.pm#Placeholders_and_Bind_Values

That said, I noticed you used both double-quotes and single-quotes in your examples.  
You need to always use single-quotes when you have a string literal in SQL, but if the 
string literal is provided by a bind variable then you don't.  For example, "select * 
from foo where bar = 'here' and baz = ?".  Double-quotes have a different meaning in 
SQL strings, for more advanced things, and beginners should avoid them for simplicity.

-- Darren Duncan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to