[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string dollar literals (for luamacro or tokenf)
- From: Petite Abeille <petite.abeille@...>
- Date: Mon, 23 Jan 2012 19:03:29 +0100
On Jan 23, 2012, at 4:50 AM, Jay Carlson wrote:
> Somebody else can write the SQL prepared statement parser ("SELECT * FROM $foo" -> {"SELECT * FROM ?", {foo}} etc)
Sadly, prepared SQL statement are not meant to substitute object names (e.g. table names), but rather just bind variables. To add insult to injury, bind variable placeholders vary from database to database. Oh, well...
So perhaps:
select * from foo where bar = $baz
Into:
select * from foo where bar = ?
Which could simply be done as string.format if one doesn't have support for proper prepared statements (e.g. luasql):
( 'select * from foo where bar = %s' ):format( escape( baz ) )
Usage example:
local aDB = DB( 'sqlite3://localhost/test.db' )
for aRow in aDB( 'select * from foo where bar = %s', 'baz' ) do
print( aRow.bar )
end
FWIW:
http://dev.alt.textdrive.com/browser/Mail/DB.lua#L148