Player APIs (BrightScript & Ja...
...
Object Reference
Hashing and Storage Objects
roSqliteStatement
8min
this object is created by calling the createstatement() method on an rosqlitedatabase object the javascript equivalent is to use the indexeddb ifsqlitestatement all bind methods return true upon success bindbyname(associative array as object) as boolean binds the sql variable(s) using the names contained in the sql statement bindbyoffset(associative array/enumerable as object) as boolean binds the sql variable(s) using the index contained in the sql statement if passed an associative array, this method will convert the keys of the associative array into numeric offsets when binding if passed an enumerable object (e g roarray ), it will bind the values of the enumerable in the order that they are stored bindtext(variable/index as object, value as string) as boolean binds the sql variable indicated by the name or index parameter to the passed string value bindinteger(variable/index as object, value as integer) as boolean binds the sql variable indicated by the name or index parameter to the passed integer value run() as integer runs the sql statement immediately and waits for the integer result the following are possible integer result codes 100 statement complete 101 busy 102 rows available runbackground() as integer runs the sql statement in the background you can use rosqlitedatabase setport() to set a message port that will receive an rosqliteevent message at a later point the runbackground() call will result in an integer transaction id, which will appear in the rosqliteevent message that matches the transaction getdata() as object returns an associative array of name/value pairs that are available after a select (or similar) operation finalise() finalizes the statement this method should be applied to statements before the parent database is closed the object should not be used after this method is called also note that objects are automatically finalized when they are deleted examples the following script inserts into a table using the bindbyname() method insertstmt = db createstatement("insert into playback (md5,path,playback count) values(\ md5 param,\ path param,\ pc param);") print insertstmt if type(insertstmt) <> "rosqlitestatement" then print "we didn't get a statement returned!!" end endif params = { md5 param "abdef12346", path param "/foo/bar/bing/bong", pc param 11 } bindresult = insertstmt bindbyname(params) if bindresult print "bindbyname ok" else print "bindbyname failed" end endif sqlresult = insertstmt run() print sqlresult if sqlresult = sqlite complete print "table insertion ok" else print "table insertion failed" endif insertstmt finalise() the following script inserts into a table in the background ' this examples assume you have set a message port on your rosqlitedatabase instance ' insertstmt = db createstatement("insert into playback (md5,path,playback count) values(\ md5 param,\ path param,\ pc param);") print insertstmt if type(insertstmt) <> "rosqlitestatement" then print "we didn't get a statement returned!!" end endif params = { md5 param "abdef12348", path param "/foo/bar/bing/bong", pc param 13 } bindresult = insertstmt bindbyname(params) if bindresult print "bindbyname ok" else print "bindbyname failed" end endif expectedid = insertstmt runbackground() e = mp waitmessage(10000) if e <> invalid then if type(e) = "rosqliteevent" then transid = e gettransactionid() sqlresult = e getsqlresult() print transid print sqlresult if transid <> expectedid then print "incorrect transaction id" end endif if sqlresult <> sqlite complete then print "sql insertion failed" end endif else print "runbackground() wrong event failed" end endif else print "runbackground() no response failed" end endif ' you don't need to call finalise() since that'll be done by the background processor the following script queries from a table selectstmt = db createstatement("select from playback;") if type(selectstmt) <> "rosqlitestatement" then print "we didn't get a statement returned!!" end endif sqlresult = selectstmt run() print sqlresult while sqlresult = sqlite rows resultsdata = selectstmt getdata() print resultsdata; sqlresult = selectstmt run() end while selectstmt finalise()