wiki:sqlite3:sqlite3_get_table
Delphi 12 Athens Updates Available!
To download, click your product: DIContainers, DIConverters, DICreole, DIFileFinder, DIGoogleReader, DIHtmlLabel, DIHtmlParser, DIMime, DIRegEx, DISQLite3, DITidy, DIUcl, DIUnicode, DIXml, YuBrotli, YuImage, YuNetSurf, YuOpenSSL, YuPcre2, YuPdf, YuStemmer, YuXmlSec, YuZip.
To download, click your product: DIContainers, DIConverters, DICreole, DIFileFinder, DIGoogleReader, DIHtmlLabel, DIHtmlParser, DIMime, DIRegEx, DISQLite3, DITidy, DIUcl, DIUnicode, DIXml, YuBrotli, YuImage, YuNetSurf, YuOpenSSL, YuPcre2, YuPdf, YuStemmer, YuXmlSec, YuZip.
Differences
This shows you the differences between two versions of the page.
— | wiki:sqlite3:sqlite3_get_table [2020/08/28 11:43] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== DISQLite3: sqlite3_get_table() example ====== | ||
+ | {{page>: | ||
+ | {{page>: | ||
+ | |||
+ | <WRAP tip>An updated version of this project is distributed with the DISQLite3 package!</ | ||
+ | |||
+ | <code delphi> | ||
+ | { DISQLite3 example showing the use of sqlite3_get_table(). | ||
+ | |||
+ | CAUTION: sqlite3_get_table() is a concenience function only. If the query | ||
+ | returns lots of data, sqlite3_get_table() will consume huge amounts of memory! | ||
+ | |||
+ | Developers are advised to stay far, far away from sqlite3_get_table() and | ||
+ | use sqlite3_prepare(), | ||
+ | |||
+ | This demo is not meant to encourage the use of sqlite3_get_table(). It was | ||
+ | written to answer a support question which explicitly asked for an example. | ||
+ | |||
+ | Visit the DISQLite3 Internet site for latest information and updates: | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Copyright (c) 2005-2017 Ralf Junker, The Delphi Inspiration < | ||
+ | |||
+ | ------------------------------------------------------------------------------ } | ||
+ | |||
+ | program DISQLite3_sqlite3_get_table; | ||
+ | |||
+ | {$APPTYPE CONSOLE} | ||
+ | {$I DI.inc} | ||
+ | {$I DISQLite3.inc} | ||
+ | |||
+ | uses | ||
+ | SysUtils, DISQLite3Api; | ||
+ | |||
+ | const | ||
+ | DB_FILENAME = ' | ||
+ | var | ||
+ | DB: sqlite3; | ||
+ | e: PAnsiChar; | ||
+ | r, c: Integer; | ||
+ | Table_Data: PPAnsiCharArray; | ||
+ | Table_Row_Count, | ||
+ | begin | ||
+ | try | ||
+ | try | ||
+ | { Create a new database with simple test table and data. } | ||
+ | DeleteFile(DB_FILENAME); | ||
+ | sqlite3_open(DB_FILENAME, | ||
+ | sqlite3_exec_fast(DB, | ||
+ | |||
+ | sqlite3_exec_fast(DB, | ||
+ | sqlite3_exec_fast(DB, | ||
+ | sqlite3_exec_fast(DB, | ||
+ | |||
+ | { Run a query using sqlite3_get_table. } | ||
+ | if sqlite3_get_table( | ||
+ | DB, // The databae handle. | ||
+ | ' | ||
+ | Pointer(@Table_Data), | ||
+ | @Table_Row_Count, | ||
+ | @Table_Column_Count, | ||
+ | @e) // Write error message here on failure. | ||
+ | = SQLITE_OK then | ||
+ | begin | ||
+ | { Query successful? Write result to console. } | ||
+ | |||
+ | { Columnn Names are first. } | ||
+ | Write(' | ||
+ | for c := 0 to Table_Column_Count - 1 do | ||
+ | begin | ||
+ | Write(Table_Data[c], | ||
+ | end; | ||
+ | WriteLn; | ||
+ | |||
+ | { Write horizontal line as data separator. } | ||
+ | Write(' | ||
+ | for c := 0 to Table_Column_Count - 1 do | ||
+ | begin | ||
+ | Write(' | ||
+ | end; | ||
+ | WriteLn; | ||
+ | |||
+ | { Row data follows next. } | ||
+ | for r := 1 to Table_Row_Count do | ||
+ | begin | ||
+ | Write(' | ||
+ | for c := 0 to Table_Column_Count - 1 do | ||
+ | begin | ||
+ | Write(Table_Data[r * Table_Column_Count + c], ' | ||
+ | end; | ||
+ | WriteLn; | ||
+ | end; | ||
+ | |||
+ | { Free allocated table data. } | ||
+ | sqlite3_free_table(Table_Data); | ||
+ | end | ||
+ | else | ||
+ | begin | ||
+ | { Failure? Output error message. } | ||
+ | WriteLn(e); | ||
+ | sqlite3_free(e); | ||
+ | end; | ||
+ | |||
+ | sqlite3_check(sqlite3_close(DB), | ||
+ | |||
+ | except | ||
+ | on e: Exception do | ||
+ | WriteLn(e.Message); | ||
+ | end; | ||
+ | |||
+ | finally | ||
+ | WriteLn; | ||
+ | WriteLn(' | ||
+ | ReadLn; | ||
+ | end; | ||
+ | end. | ||
+ | </ |