|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-01-09 12:48 UTC] cagret at gmail dot com
Description:
------------
Sqlite3Result->columnType() always returns SQLITE3_NULL.
Table structure:
CREATE TABLE IF NOT EXISTS Test (Id int primary key, Name varchar(50));
Reproduce code:
---------------
$query = sprintf('SELECT * FROM %s', $table);
$result = $db->query($query);
$columns = array();
$numcols = $result->numColumns();
for ($i = 0; $i < $numcols; $i++) {
$colname = $result->columnName($i);
$coltype = $result->columnType($i);
}
$coltype == 5 (SQLITE3_NULL) for each column.
Expected result:
----------------
SQLITE3_INTEGER or SQLITE3_TEXT
Actual result:
--------------
SQLITE3_NULL
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
What do you mean by "no type conversions have occured", "as described below" > am I missing something? Where in my code am I making any type conversions? I don't quite understand, what is this function for, if it always returns SQLITE3_NULL ? I was creating a web based browser for sqlite3 database files, in column headers I want to display column type: Id (int) | Name (varchar) That's all, what is the way of doing that? I've found a solution, but it looks like a way around, using columnType() would be easier. I am parsing the "CREATE TABLE..." sql that i fetch by querying sqlite_master table, using a simple regexp. Here is the function: function sqlite3_columns($table) { global $db; // $result->columnType(0) - bug, always returns SQLITE3_NULL $query = sprintf("SELECT * FROM sqlite_master WHERE type='table' and name='%s'", $table); $result = $db->query($query); $row = $result->fetchArray(SQLITE3_ASSOC); $result->finalize(); $sql = $row['sql']; preg_match_all('#[\(,]\s*(\w+)\s+(\w+)#', $sql, $pmatch); $columns = array(); foreach ($pmatch[1] as $k => $colname) { $columns[] = array('name'=>$colname, 'type'=>$pmatch[2][$k]); } return $columns; }