Squirrel/Server/Functions/SQLite/sqlite column data

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with '{{Squirrel/Title|sqlite_column_data}} {{RequiresModule|lu_sqlite|Modules/Squirrel/lu_sqlite}} This function returns the column count in the query result struct. Note that column …')
 
Line 14: Line 14:
 
== Example ==
 
== Example ==
  
Some explanation here.
+
This will print the returned data if there is any when someone types 'result' into the server console.
{{Squirrel/NeedsExample}}
+
  
 
<code lang="squirrel">
 
<code lang="squirrel">
-- Todo
+
function onScriptLoad()
 +
{
 +
LoadModule( "lu_sqlite" );
 +
pSQDatabase <- sqlite_open( "database.sqlite" );
 +
 +
return 1;
 +
}
 +
 
 +
function onConsoleInput( szCommand, szText )
 +
{
 +
if ( szCommand == "result" )
 +
{
 +
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 );
 +
else print( "No data found!" );
 +
}
 +
}
 +
 +
return 1;
 +
}
 
</code>
 
</code>
  
 
=== Notes ===
 
=== Notes ===
  
-- List of used functions and other notes here.
+
The function [[Squirrel/Server/Functions/Scripts/LoadModule|LoadModule]] and [[Squirrel/Server/Functions/SQLite/sqlite_open|sqlite_open]] 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 16:57, 25 October 2010

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events
Note: This function requires the external module lu_sqlite.

This function returns the column count in the query result struct. Note that column values are automatically converted to integers, floats or strings. If the result struct has no rows/columns, the function will return null.

Syntax

  1. int/float/string sqlite_column_count( UserPointer result, int column )

Arguments

  • result - This is a pointer to a result struct retrieved from sqlite_query or sqlite_next_row
  • column - This is the column you wish to return the value for. Column indexes begin from 0

Example

This will print the returned data if there is any when someone types 'result' into the server console.

  1.  
  2. function onScriptLoad()
  3. {
  4. LoadModule( "lu_sqlite" );
  5. pSQDatabase <- sqlite_open( "database.sqlite" );
  6. return 1;
  7. }
  8.  
  9. function onConsoleInput( szCommand, szText )
  10. {
  11. if ( szCommand == "result" )
  12. {
  13. local query = sqlite_query( pSQDatabase, "SELECT Foo FROM Bar WHERE FooBar='" + szText + "'" );
  14. if ( query )
  15. {
  16. local data = sqlite_columndata( query, 0 );
  17. if ( data ) print( "Result: " + data );
  18. else print( "No data found!" );
  19. }
  20. }
  21. return 1;
  22. }
  23.  

Notes

The function LoadModule and sqlite_open 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.

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox