Example #1
1
<?php

if (!extension_loaded("sqlite")) {
    dl("sqlite.so");
    if (!extension_loaded("sqlite")) {
        exit("Please enable SQLite support\n");
    }
}
debug_zval_dump(sqlite_libversion());
debug_zval_dump(sqlite_libencoding());
$s = sqlite_open("weztest.sqlite", 0666, $err);
debug_zval_dump($err);
debug_zval_dump($s);
$r = sqlite_query("create table foo (a INTEGER PRIMARY KEY, b INTEGER )", $s);
debug_zval_dump(sqlite_last_error($s));
debug_zval_dump(sqlite_error_string(sqlite_last_error($s)));
$r = sqlite_query("select *, php('md5', sql) as o from sqlite_master", $s);
debug_zval_dump($r);
debug_zval_dump(sqlite_num_rows($r));
debug_zval_dump(sqlite_num_fields($r));
for ($j = 0; $j < sqlite_num_fields($r); $j++) {
    echo "Field {$j} is " . sqlite_field_name($r, $j) . "\n";
}
while ($row = sqlite_fetch_array($r, SQLITE_ASSOC)) {
    print_r($row);
}
sqlite_close($s);
 public function getNFields()
 {
     if ($this->_nfields === null) {
         $this->_nfields = sqlite_num_fields($this->r);
     }
     return $this->_nfields;
 }
Example #3
0
 public function columnCount()
 {
     if ($this->_result) {
         return sqlite_num_fields($this->_result);
     }
     return 0;
 }
 /**
  * Public method:
  *	Checks if query was valid and returns how may fields returns
  *       	this->columnCount( void ):Void
  */
 function columnCount()
 {
     $result = 0;
     if (!is_null($this->__result)) {
         $result = sqlite_num_fields($this->__result);
     }
     return $result;
 }
Example #5
0
 /**
  * Internal method to get a list of field names returned
  *
  * @return Integer
  */
 public function getFields()
 {
     $fields = sqlite_num_fields($this->result);
     $result = array();
     for ($i = 0; $i < $fields; $i++) {
         $result[$i] = sqlite_field_name($this->result, $i);
     }
     return $result;
 }
 /**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result)
 {
     $fields = array();
     if (is_resource($result)) {
         for ($i = 0, $num = sqlite_num_fields($result); $i < $num; $i++) {
             $fields[sqlite_field_name($result, $i)] = FALSE;
             // Types are unknown
         }
     }
     parent::__construct($result, $fields);
 }
Example #7
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function sqliteAdapter($d)
 {
     parent::RecordSetAdapter($d);
     // grab all of the rows
     $fieldcount = sqlite_num_fields($d);
     // loop over all of the fields
     for ($i = 0; $i < $fieldcount; $i++) {
         // decode each field name ready for encoding when it goes through serialization
         // and save each field name into the array
         $this->columns[] = sqlite_field_name($d, $i);
     }
     if (sqlite_num_rows($d) > 0) {
         $this->rows = sqlite_fetch_all($d, SQLITE_NUM);
     }
 }
Example #8
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function sqliteAdapter($d)
 {
     parent::RecordSetAdapter($d);
     // grab all of the rows
     $fieldcount = sqlite_num_fields($d);
     $ob = "";
     $fc = pack('N', $fieldcount);
     if (sqlite_num_rows($d) > 0) {
         sqlite_seek($d, 0);
         while ($line = sqlite_fetch_array($d, SQLITE_NUM)) {
             //Write array flag + length
             $ob .= "\n" . $fc;
             $to = count($line);
             for ($i = 0; $i < $to; $i++) {
                 //Type everything as a string since this is sqlite
                 $value = $line[$i];
                 $os = $this->_directCharsetHandler->transliterate($value);
                 //string flag, string length, and string
                 $len = strlen($os);
                 if ($len < 65536) {
                     $ob .= "" . pack('n', $len) . $os;
                 } else {
                     $ob .= "\f" . pack('N', $len) . $os;
                 }
             }
         }
     }
     // grab the number of fields
     // loop over all of the fields
     for ($i = 0; $i < $fieldcount; $i++) {
         // decode each field name ready for encoding when it goes through serialization
         // and save each field name into the array
         $this->columnNames[$i] = $this->_directCharsetHandler->transliterate(sqlite_field_name($d, $i));
     }
     $this->numRows = sqlite_num_rows($d);
     $this->serializedData = $ob;
 }
Example #9
0
 function getFieldInfo($stack = 0)
 {
     $fields = array();
     $i = 0;
     if (($table = Session::get('select', 'table')) != '') {
         // query from a table, so we can find keys related information using pragma
         $this->result['_tinfo'] = @sqlite_query('PRAGMA table_info(' . $this->quote($table) . ')', $this->conn);
         while ($row = $this->fetchRow('_tinfo')) {
             $f = new StdClass();
             $f->name = $row['name'];
             $f->table = $table;
             $f->not_null = $row['notnull'];
             $f->blob = $row['type'] == 'BLOB' ? 1 : 0;
             $f->pkey = $row['pk'];
             $f->ukey = 0;
             $f->mkey = 0;
             $f->zerofill = 0;
             $f->unsigned = 0;
             $f->autoinc = 0;
             $f->numeric = $row['type'] == 'INTEGER' ? 1 : 0;
             $f->type = $row['type'] == 'INTEGER' ? 'numeric' : ($row['type'] == 'BLOB' ? 'binary' : 'text');
             $fields[] = $f;
             $i++;
         }
     } else {
         while ($i < sqlite_num_fields($this->result[$stack])) {
             $f = new StdClass();
             $f->name = sqlite_field_name($this->result[$stack], $i);
             $f->table = '';
             $f->not_null = 0;
             $f->blob = 0;
             $f->pkey = 0;
             $f->ukey = 0;
             $f->mkey = 0;
             $f->zerofill = 0;
             $f->unsigned = 0;
             $f->autoinc = 0;
             $f->numeric = 0;
             $f->type = 'string';
             $fields[] = $f;
             $i++;
         }
     }
     return $fields;
 }
 function sql_num_fields($sqltype, $result)
 {
     if ($sqltype == 'mysql') {
         if (class_exists('mysqli_result')) {
             return $result->field_count;
         } elseif (function_exists('mysql_num_fields')) {
             return mysql_num_fields($result);
         }
     } elseif ($sqltype == 'mssql') {
         if (function_exists('sqlsrv_num_fields')) {
             return sqlsrv_num_fields($result);
         } elseif (function_exists('mssql_num_fields')) {
             return mssql_num_fields($result);
         }
     } elseif ($sqltype == 'pgsql') {
         return pg_num_fields($result);
     } elseif ($sqltype == 'oracle') {
         return oci_num_fields($result);
     } elseif ($sqltype == 'sqlite3') {
         return $result->numColumns();
     } elseif ($sqltype == 'sqlite') {
         return sqlite_num_fields($result);
     } elseif ($sqltype == 'odbc') {
         return odbc_num_fields($result);
     } elseif ($sqltype == 'pdo') {
         return $result->columnCount();
     }
 }
Example #11
0
 public function columnCount()
 {
     return $this->_result ? sqlite_num_fields($this->_result) : 0;
 }
Example #12
0
 /**
  * Returns metadata for all columns in a result set.
  *
  * @return array
  */
 public function getColumnsMeta()
 {
     $count = sqlite_num_fields($this->resultSet);
     $meta = array();
     for ($i = 0; $i < $count; $i++) {
         // items 'name' and 'table' are required
         $meta[] = array('name' => sqlite_field_name($this->resultSet, $i), 'table' => NULL);
     }
     return $meta;
 }
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getResultColumns()
 {
     $count = sqlite_num_fields($this->resultSet);
     $columns = array();
     for ($i = 0; $i < $count; $i++) {
         $name = str_replace(array('[', ']'), '', sqlite_field_name($this->resultSet, $i));
         $pair = explode('.', $name);
         $columns[] = array('name' => isset($pair[1]) ? $pair[1] : $pair[0], 'table' => isset($pair[1]) ? $pair[0] : NULL, 'fullname' => $name, 'nativetype' => NULL);
     }
     return $columns;
 }
Example #14
0
 function _initrs()
 {
     $this->_numOfRows = @sqlite_num_rows($this->_queryID);
     $this->_numOfFields = @sqlite_num_fields($this->_queryID);
 }
 function num_fields($resId = null)
 {
     if ($resId == null) {
         $resId = $this->resId;
     }
     if (DEBUG) {
         $out = sqlite_num_fields($resId);
     } else {
         $out = @sqlite_num_fields($resId);
     }
     return $out;
 }
function sql_num_fields($sqltype, $hasil)
{
    if ($sqltype == 'mysql') {
        if (function_exists('mysql_num_fields')) {
            return mysql_num_fields($hasil);
        }
    } elseif ($sqltype == 'mssql') {
        if (function_exists('mssql_num_fields')) {
            return mssql_num_fields($hasil);
        } elseif (function_exists('sqlsrv_num_fields')) {
            return sqlsrv_num_fields($hasil);
        }
    } elseif ($sqltype == 'pgsql') {
        if (function_exists('pg_num_fields')) {
            return pg_num_fields($hasil);
        }
    } elseif ($sqltype == 'oracle') {
        if (function_exists('oci_num_fields')) {
            return oci_num_fields($hasil);
        }
    } elseif ($sqltype == 'sqlite3') {
        if (class_exists('SQLite3')) {
            return $hasil->numColumns();
        }
    } elseif ($sqltype == 'sqlite') {
        if (function_exists('sqlite_num_fields')) {
            return sqlite_num_fields($hasil);
        }
    } elseif ($sqltype == 'odbc') {
        if (function_exists('odbc_num_fields')) {
            return odbc_num_fields($hasil);
        }
    } elseif ($sqltype == 'pdo') {
        if (class_exists('PDO')) {
            return $hasil->columnCount();
        }
    }
}
Example #17
0
 /**
  * Retourne les données d'une table de la base de données sous forme de requètes SQL de type DML
  * 
  * @param string $tablename  Nom de la table à considérer
  * 
  * @access public
  * @return string
  */
 function get_table_data($tablename)
 {
     global $db;
     $contents = '';
     $sql = 'SELECT * FROM ' . $tablename;
     if (!($result = $db->query($sql))) {
         trigger_error('Impossible d\'obtenir le contenu de la table ' . $tablename, ERROR);
     }
     $result->setFetchMode(SQL_FETCH_ASSOC);
     if ($row = $result->fetch()) {
         $contents = $this->eol;
         $contents .= '-- ' . $this->eol;
         $contents .= '-- Contenu de la table ' . $tablename . ' ' . $this->eol;
         $contents .= '-- ' . $this->eol;
         $fields = array();
         for ($j = 0, $n = sqlite_num_fields($result->result); $j < $n; $j++) {
             $fields[] = sqlite_field_name($result->result, $j);
         }
         $fields = implode(', ', $fields);
         do {
             $contents .= "INSERT INTO {$tablename} ({$fields}) VALUES";
             foreach ($row as $key => $value) {
                 if (is_null($value)) {
                     $row[$key] = 'NULL';
                 } else {
                     $row[$key] = '\'' . $db->escape($value) . '\'';
                 }
             }
             $contents .= '(' . implode(', ', $row) . ');' . $this->eol;
         } while ($row = $result->fetch());
     }
     return $contents;
 }
 /**
  * Method to fetch fields information of resultset
  *
  * @return  array
  */
 public function fetch_fields()
 {
     $_fields_info = array();
     $_f = 0;
     $_field_num = sqlite_num_fields($this->res_result);
     while ($_f < $_field_num) {
         $field_obj = new simbio_sqlite_field_info();
         $field_obj->name = sqlite_field_name($this->res_result, $_f);
         $field_obj->type = 'VARCHAR';
         $_fields_info[] = $field_obj;
         $_f++;
     }
     return $_fields_info;
 }
Example #19
0
 function num_fields($query_id = 0)
 {
     return $query_id ? @sqlite_num_fields($query_id) : false;
 }
    $text = 'Bug information could not be gathered.';
}
$email_text = str_replace('BUGS_CLOSED', $text, $email_text);
/****************************************************************************/
/**** Weekly notes stats ****************************************************/
/****************************************************************************/
// Note: notes_stats.sqlite is generated via web/doc/trunk/scripts/notes*.php
// It's used for other note related activities, but we're using it for this too.
$dbfile = SQLITE_DIR . 'notes_stats.sqlite';
$text = '';
if (is_readable($dbfile) && ($db = sqlite_open($dbfile, 0666))) {
    $seconds = 86400 * DAYS_LOOKUP;
    $sql = "SELECT who, count(*) as count FROM notes WHERE time > (strftime('%s', 'now')-{$seconds}) GROUP BY who ORDER BY count DESC";
    $res = sqlite_query($db, $sql);
    if ($res) {
        if (sqlite_num_fields($res) > 0) {
            $rows = sqlite_fetch_all($res, SQLITE_ASSOC);
            foreach ($rows as $row) {
                $text .= sprintf("%20s %5s\n", $row['who'], $row['count']);
            }
        } else {
            $text = 'No notes were edited last week. So sad. :(';
        }
    } else {
        $text = 'Unable to query the notes database';
    }
} else {
    $text = 'The notes data cannot be found';
}
$email_text = str_replace('NOTES_HANDLED', $text, $email_text);
/**** Misc ******************************************************************/
Example #21
0
function sqlitem_num_fields($result)
{
    return sqlite_num_fields($result);
}
Example #22
0
 public function num_fields($result)
 {
     return sqlite_num_fields($result);
 }
Example #23
0
 /**
  * Gets the number of columns in a result set.
  *
  * @return number of columns in a result set
  */
 function numCols($result)
 {
     $cols = @sqlite_num_fields($result);
     if (!$cols) {
         return $this->sqliteRaiseError();
     }
     return $cols;
 }
Example #24
0
 function num_fields(&$q)
 {
     return sqlite_num_fields($q);
 }
Example #25
0
 function query($query)
 {
     // For reg expressions
     $query = str_replace("/[\n\r]/", '', trim($query));
     // initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     $this->result = @sqlite_query($this->dbh, $query);
     $this->count(true, true);
     // If there is an error then take note of it..
     if (@sqlite_last_error($this->dbh)) {
         $err_str = sqlite_error_string(sqlite_last_error($this->dbh));
         $this->register_error($err_str);
         $this->show_errors ? trigger_error($err_str, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @sqlite_changes($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $this->insert_id = @sqlite_last_insert_rowid($this->dbh);
         }
         // Return number fo rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         while ($i < @sqlite_num_fields($this->result)) {
             $this->col_info[$i]->name = sqlite_field_name($this->result, $i);
             $this->col_info[$i]->type = null;
             $this->col_info[$i]->max_length = null;
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sqlite_fetch_array($this->result, SQLITE_ASSOC)) {
             // Store relults as an objects within main array
             $obj = (object) $row;
             //convert to object
             $this->last_result[$num_rows] = $obj;
             $num_rows++;
         }
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
Example #26
0
 /**
  * Count the number of columns returned by the DBMS in a query result.
  *
  * @access public
  * @return mixed integer value with the number of columns, a MDB2 error
  *                       on failure
  */
 function numCols()
 {
     $cols = @sqlite_num_fields($this->result);
     if (is_null($cols)) {
         if (is_null($this->result)) {
             return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'numCols: resultset has already been freed');
         }
         return $this->mdb->raiseError();
     }
     return $cols;
 }
Example #27
0
 /**
  * Count the number of columns returned by the DBMS in a query result.
  *
  * @access public
  * @return mixed integer value with the number of columns, a MDB2 error
  *                       on failure
  */
 function numCols()
 {
     $cols = @sqlite_num_fields($this->result);
     if (is_null($cols)) {
         if ($this->result === false) {
             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'resultset has already been freed', __FUNCTION__);
         } elseif (is_null($this->result)) {
             return count($this->types);
         }
         return $this->db->raiseError(null, null, null, 'Could not get column count', __FUNCTION__);
     }
     return $cols;
 }
Example #28
0
 /**
  * Get the number of fields in the resultset.
  */
 function num_fields($request)
 {
     return sqlite_num_fields($request);
 }
Example #29
0
 /**
  * Number of fields in the result set
  *
  * @access	public
  * @return	integer
  */
 function num_fields()
 {
     return @sqlite_num_fields($this->result_id);
 }
Example #30
0
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->results =& $results;
     $this->map = array();
     $num_fields = sqlite_num_fields($results);
     $index = 0;
     $j = 0;
     while ($j < $num_fields) {
         $columnName = str_replace('"', '', sqlite_field_name($results, $j));
         if (strpos($columnName, '.')) {
             $parts = explode('.', $columnName);
             $this->map[$index++] = array($parts[0], $parts[1]);
         } else {
             $this->map[$index++] = array(0, $columnName);
         }
         $j++;
     }
 }