#50707 [Bgs]: Sqlite3Result->columnType() always returns SQLITE3_NULL

From: Date: Mon, 11 Jan 2010 05:15:19 +0000
Subject: #50707 [Bgs]: Sqlite3Result->columnType() always returns SQLITE3_NULL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146518@lists.php.net to get a copy of this message
ID: 50707 User updated by: cagret at gmail dot com Reported By: cagret at gmail dot com Status: Bogus Bug Type: SQLite related Operating System: Win xp pro PHP Version: 5.3.1 New Comment: 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; } Previous Comments: ------------------------------------------------------------------------ [2010-01-11 02:47:53] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The value returned by sqlite3_column_type() is only meaningful if no type conversions have occurred as described below. After a type conversion, the value returned by sqlite3_column_type() is undefined. ------------------------------------------------------------------------ [2010-01-09 12:48:35] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50707&edit=1

« previous php.bugs (#146518) next »