User Tools

Site Tools


lua:db:exec

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:db:exec [2016/02/08 05:06] vodurlua:db:exec [2016/02/08 05:37] (current) vodur
Line 1: Line 1:
-db.exec( statement )+<font 18px/inherit;;inherit;;inherit>** db.exec( statement ) **</font>
  
 Execute sql statement. Execute sql statement.
  
 If statement is a query, return value is a table with the query results. If statement is a query, return value is a table with the query results.
 +
 +See also [[:lua:db:escape|db.escape()]].
 +
 +===== Examples: =====
  
 Check if a table exists: Check if a table exists:
Line 43: Line 47:
 for _,entry in pairs(animals) do for _,entry in pairs(animals) do
     db.exec( ([[INSERT INTO grraka_animals(animal_name, location)     db.exec( ([[INSERT INTO grraka_animals(animal_name, location)
-                      VALUES( %s, %s)]]):format( db.escape(entry.animal_name), db.escape(entry.location))+                      VALUES( '%s''%s')]]):format( db.escape(entry.animal_name), db.escape(entry.location))
 end end
 db.exec[[END]] db.exec[[END]]
Line 51: Line 55:
  
 <code lua> <code lua>
-local result=[[SELECT animal_name, location FROM grraka_animals ORDER BY animal_name]]+local result=db.exec[[SELECT animal_name, location FROM grraka_animals ORDER BY animal_name]]
  
 for _,row in result do for _,row in result do
Line 57: Line 61:
 end end
 </code> </code>
 +
 +See sqlite3 general documentation for further reference on statements.
  
lua/db/exec.1454908013.txt.gz · Last modified: 2016/02/08 05:06 by vodur