Squirrel/Server/Functions/SQLite/sqlite next row
From Liberty Unleashed Wiki
(Difference between revisions)
(Created page with '{{Squirrel/Title|sqlite_next_row}} {{RequiresModule|lu_sqlite|Modules/Squirrel/lu_sqlite}} This function returns the next result row of the query result struct. If the query has …') |
|||
Line 13: | Line 13: | ||
== Example == | == Example == | ||
− | + | This will see if anymore data is in the results when 'nextrow' is typed into the server console. | |
− | + | ||
<code lang="squirrel"> | <code lang="squirrel"> | ||
− | - | + | function onScriptLoad() |
+ | { | ||
+ | LoadModule( "lu_sqlite" ); | ||
+ | pSQDatabase <- sqlite_open( "database.sqlite" ); | ||
+ | |||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | function onConsoleInput( szCommand, szText ) | ||
+ | { | ||
+ | if ( szCommand == "nextrow" ) | ||
+ | { | ||
+ | local query = sqlite_query( pSQDatabase, "SELECT Foo FROM Bar WHERE FooBar='" + szText + "'" ); | ||
+ | if ( query ) | ||
+ | { | ||
+ | local data = sqlite_columndata( query, 0 ); | ||
+ | if ( data ) | ||
+ | { | ||
+ | print( "Result: " + data ); | ||
+ | local data2 = sqlite_next_row( data ); | ||
+ | if ( data2 ) print( "Result 2: " + data2 ); | ||
+ | else print( "No moar data found!" ); | ||
+ | } | ||
+ | else print( "No data found!" ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return 1; | ||
+ | } | ||
</code> | </code> | ||
=== Notes === | === Notes === | ||
− | + | The function [[Squirrel/Server/Functions/Scripts/LoadModule|LoadModule]] and [[Squirrel/Server/Functions/SQLite/sqlite_open|sqlite_open]] and [[Squirrel/Server/Functions/SQLite/sqlite_open|sqlite_query]] and [[Squirrel/Server/Functions/Misc/print|print]] and event [[Squirrel/Server/Events/Misc/onScriptLoad|onScriptLoad]] and [[Squirrel/Server/Events/Misc/onConsoleInput|onConsoleInput]] were used in this example. More info about them in the corresponding pages. | |
For a larger example, check the [[Squirrel/Examples/SQLite|SQLite database example]] from the wiki tutorials. | For a larger example, check the [[Squirrel/Examples/SQLite|SQLite database example]] from the wiki tutorials. |
Revision as of 17:04, 25 October 2010
Note: This function requires the external module lu_sqlite.
This function returns the next result row of the query result struct. If the query has no more result rows the function will return null, otherwise it will return a pointer to the next row.
Syntax
UserPointer sqlite_next_row( UserPointer result )
Arguments
- result - This is a pointer to a result struct retrieved from sqlite_query or another iteration of sqlite_next_row
Example
This will see if anymore data is in the results when 'nextrow' is typed into the server console.
function onScriptLoad() { LoadModule( "lu_sqlite" ); pSQDatabase <- sqlite_open( "database.sqlite" ); return 1; } function onConsoleInput( szCommand, szText ) { if ( szCommand == "nextrow" ) { local query = sqlite_query( pSQDatabase, "SELECT Foo FROM Bar WHERE FooBar='" + szText + "'" ); if ( query ) { local data = sqlite_columndata( query, 0 ); if ( data ) { print( "Result: " + data ); local data2 = sqlite_next_row( data ); if ( data2 ) print( "Result 2: " + data2 ); else print( "No moar data found!" ); } else print( "No data found!" ); } } return 1; }
Notes
The function LoadModule and sqlite_open and sqlite_query and print and event onScriptLoad and onConsoleInput were used in this example. More info about them in the corresponding pages.
For a larger example, check the SQLite database example from the wiki tutorials.
Related Functions
These functions are provided by the official module lu_sqlite.
- sqlite_close
- sqlite_column_count
- sqlite_column_data
- sqlite_free
- sqlite_next_row
- sqlite_open
- sqlite_query