joelwe

Untitled

Mar 28th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. require "sqlite3"
  2.  
  3. local test =
  4. {
  5.     1229,1230,731,738,1231,735,734,2171,736,750,751,4135,3840,4134,2205,1225,1233,1232,1234,2197,1228,3841,1226,1227
  6. }
  7.  
  8. -- Does the database exist in the documents directory (allows updating and persistance)
  9. local path = system.pathForFile("kalori.sqlite", system.DocumentsDirectory )
  10. file = io.open( path, "r" )
  11.    if( file == nil )then          
  12.     -- Doesn't Already Exist, So Copy it In From Resource Directory                          
  13.     pathSource     = system.pathForFile( "kalori.sqlite", system.ResourceDirectory )  
  14.     fileSource = io.open( pathSource, "r" )
  15.     contentsSource = fileSource:read( "*a" )                                  
  16.         --Write Destination File in Documents Directory                                  
  17.         pathDest = system.pathForFile( "kalori.sqlite", system.DocumentsDirectory )                
  18.         fileDest = io.open( pathDest, "w" )                
  19.         fileDest:write( contentsSource )                
  20.          -- Done                      
  21.         io.close( fileSource )        
  22.         io.close( fileDest )        
  23.    end  
  24.  
  25. local db = sqlite3.open( path )
  26.  
  27. for i = 1, #test do
  28.     db:exec([[UPDATE Food SET Maincat=2 WHERE ID = ']]..test[i]..[[';]])
  29. end
Advertisement
Add Comment
Please, Sign In to add comment