On Tue, 15 Jan 2008 11:33:06 -0800 (PST), "kamil.szot" <[EMAIL PROTECTED]>
wrote:
>
>
>Gilles Ganault wrote:
>>
>> So the options are:
>> 1. use the old SQLite2 sqlite_() functions (or some class that turns this
>> into OO)
>> 2. PDO to use the SQLite3 linked-in library
>> 3. PDO to access the SQLite3 DLL
>>
>> ... with 2 being the recommended choice.
>>
>With 2 (and probably 3) you will not be able to retrieve metadata (for
>example column names) for empty table.
>The only way of getting column names in PDO is executing "SELECT * FROM
>table" query and then retrieving metadata using columnCount() and
>getColumnMeta() methods of PDOStatement object returned by PDO->query()
>method. But in case of sqlite: (meaning sqlite3) databases getColumnMeta()
>returns nothing if result set is empty. In case sqlite2: driver
>getColumnMeta() always throws exception.
>
>So if you will be needing to inspect your tables at runtime then I'm
>recommending first solution.
>
>If anyone knows how to get field names of a table from sqlite3 database in
>PHP please share your knowledge with the world. :-)
There's a PRAGMA for that purpose.
$sql = "PRAGMA table_info('tablename')";
$res = $this->query($sql);
Example result set:
cid name type notnull dflt_value pk
0 jobid INTEGER 99 1
1 TSN CHAR(4) 0 0
2 jobprio INTEGER 0 9 0
3 status CHAR(1) 0 'W' 0
4 userid VARCHAR(8) 99 0
etc.
The columns of this resultset have metadata, just like a normal resultset.
Tested with:
php, php_pdo.dll, php_pdo_sqlite_external.dll v5.2.5.5 (2007-11-08, Windows),
sqlite3.dll v3.5.4 (2007-12-14)
--
( Kees Nuyt
)
c[_]
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------