/** * Method to send SQL query * * @param resource $res_conn * @return void */ private function sendQuery($res_conn) { // checking query type // if the query return recordset or not if (preg_match("/^(SELECT)\\s/i", $this->sql_string)) { $this->res_result = @sqlite_query($res_conn, $this->sql_string); // error checking if (!$this->res_result) { $this->errno = sqlite_last_error($res_conn); $this->error = "Query failed to executed. Please check your query again. \n" . sqlite_error_string($this->errno); } else { // count number of rows $this->num_rows = @sqlite_num_rows($this->res_result); } } else { $_query = @sqlite_unbuffered_query($res_conn, $this->sql_string); $this->insert_id = sqlite_last_insert_rowid($res_conn); // error checking if (!$_query) { $this->errno = sqlite_last_error($res_conn); $this->error = "Query failed to executed. Please check your query again. \n" . sqlite_error_string($this->errno); } else { // get number of affected row $this->affected_rows = @sqlite_changes($res_conn); } // nullify query $_query = null; } }
function query($sql, $unbuffered = false) { if (strlen($sql) > 140000) { exit('Insane query. Aborting.'); } if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) { $q_start = forum_microtime(); } if ($unbuffered) { $this->query_result = @sqlite_unbuffered_query($this->link_id, $sql); } else { $this->query_result = @sqlite_query($this->link_id, $sql); } if ($this->query_result) { if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) { $this->saved_queries[] = array($sql, sprintf('%.5f', forum_microtime() - $q_start)); } ++$this->num_queries; return $this->query_result; } else { if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) { $this->saved_queries[] = array($sql, 0); } $this->error_no = @sqlite_last_error($this->link_id); $this->error_msg = @sqlite_error_string($this->error_no); if ($this->in_transaction) { @sqlite_query($this->link_id, 'ROLLBACK'); } --$this->in_transaction; return false; } }
/** * {@inheritdoc} */ public function write_data($table_name) { if (!$this->is_initialized) { throw new extractor_not_initialized_exception(); } $col_types = sqlite_fetch_column_types($this->db->get_db_connect_id(), $table_name); $sql = "SELECT *\n\t\t\tFROM {$table_name}"; $result = sqlite_unbuffered_query($this->db->get_db_connect_id(), $sql); $rows = sqlite_fetch_all($result, SQLITE_ASSOC); $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES ('; foreach ($rows as $row) { foreach ($row as $column_name => $column_data) { if (is_null($column_data)) { $row[$column_name] = 'NULL'; } else { if ($column_data == '') { $row[$column_name] = "''"; } else { if (strpos($col_types[$column_name], 'text') !== false || strpos($col_types[$column_name], 'char') !== false || strpos($col_types[$column_name], 'blob') !== false) { $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data)); } } } } $this->flush($sql_insert . implode(', ', $row) . ");\n"); } }
function query($sql, $unbuffered = false) { if (defined('LUNA_SHOW_QUERIES')) { $q_start = get_microtime(); } if ($unbuffered) { $this->query_result = @sqlite_unbuffered_query($this->link_id, $sql); } else { $this->query_result = @sqlite_query($this->link_id, $sql); } if ($this->query_result) { if (defined('LUNA_SHOW_QUERIES')) { $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start)); } ++$this->num_queries; return $this->query_result; } else { if (defined('LUNA_SHOW_QUERIES')) { $this->saved_queries[] = array($sql, 0); } $this->error_no = @sqlite_last_error($this->link_id); $this->error_msg = @sqlite_error_string($this->error_no); if ($this->in_transaction) { @sqlite_query($this->link_id, 'ROLLBACK'); } --$this->in_transaction; return false; } }
/** * クエリを実行する。 * * @param string $query SQL文。 * @return Resource $result 失敗した場合は例外を投げる。 */ function query($query) { $result = sqlite_unbuffered_query($this->link, $query); if ($result == false) { throw new DBException('クエリを実行できませんでした。', $query, $this->link); } return $result; }
/** * 执行一个数据库查询语句,并返回第一行结果 * @param string $sql * @return array * @throws Exception */ public function queryAndFetch($sql) { if (!$this->db) { throw new Exception("sqlite db not connected error"); } if ($this->sqlite_version == 2) { return sqlite_fetch_array(sqlite_unbuffered_query($this->db, $sql)); } else { return $this->db->query($sql)->fetch(); } }
public function query($query) { $result_set = sqlite_unbuffered_query($query, $this->_connection, $this->_dbinfo); if ($result_set) { $result = array(); while ($row = sqlite_fetch_array($result_set, SQLITE_ASSOC)) { array_push($result, $row); } } else { $this->_setErrors('SQLER'); $result = false; } return $result; }
public function add($ip, $comment) { $comment = self::trunc($comment); $ip = "'" . sqlite_escape_string($ip) . "'"; if ($comment == '') { sqlite_exec($this->handle, "delete from comments where ip=" . $ip, $this->error); } else { $comment = "'" . sqlite_escape_string($comment) . "'"; if (($query = sqlite_unbuffered_query($this->handle, "select count(comment) from comments where ip=" . $ip, SQLITE_ASSOC, $this->error)) && sqlite_fetch_single($query)) { sqlite_exec($this->handle, "update comments set comment=" . $comment . " where ip=" . $ip, $this->error); } else { sqlite_exec($this->handle, "insert into comments (ip,comment) values (" . $ip . "," . $comment . ")", $this->error); } } }
function connect($_DB) { $this->pre = $_DB['prefix']; if ($this->pconnect) { $this->conn = sqlite_popen(INC_P . '/data/' . $_DB['database'], 0666, $sqliteerror); } else { $this->conn = sqlite_open(INC_P . '/data/' . $_DB['database'], 0666, $sqliteerror); } if (!$this->conn) { var_dump($sqliteerror); $this->halt("Can not connect SQLite Database"); } if ($_DB['charset']) { @sqlite_unbuffered_query("SET NAMES '" . $_DB['charset'] . "'"); } return true; }
function query($query) { parent::query($query); if ($this->db != null) { // submit query $this->result = @sqlite_unbuffered_query($this->db, $query); if ($this->result != false) { return true; // save error msg } else { $this->error = @sqlite_error_string(sqlite_last_error($this->db)); $this->result = null; return false; } } else { return false; } }
function query($sql, $unbuffered = false) { if ($unbuffered) { $this->query_result = @sqlite_unbuffered_query($this->link_id, $sql); } else { $this->query_result = @sqlite_query($this->link_id, $sql); } if ($this->query_result) { if (defined('EPS_DEBUG')) { $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start)); } return $this->query_result; } else { if (defined('EPS_DEBUG')) { $this->saved_queries[] = array($sql, 0); } $this->error_no = @sqlite_last_error($this->link_id); $this->error_msg = @sqlite_error_string($this->error_no); return false; } }
function query($sqlString, $buffered = true, $assign = true) { if (substr(trim($sqlString), -1) != ';') { $sqlString .= ';'; } if ($buffered) { if (DEBUG) { $resId = sqlite_query($this->connId, $sqlString); } else { $resId = @sqlite_query($this->connId, $sqlString); } } else { if (DEBUG) { $resId = sqlite_unbuffered_query($this->connId, $sqlString); } else { $resId = @sqlite_unbuffered_query($this->connId, $sqlString); } } if ($assign) { $this->resId = $resId; } return $resId; }
/** * Executes the SQL query. * * @param string SQL statement. * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) { DibiDriverException::tryError(); if ($this->buffered) { $this->resultSet = sqlite_query($this->connection, $sql); } else { $this->resultSet = sqlite_unbuffered_query($this->connection, $sql); } if (DibiDriverException::catchError($msg)) { throw new DibiDriverException($msg, sqlite_last_error($this->connection), $sql); } return is_resource($this->resultSet) ? clone $this : NULL; }
if ($subject) { $flag = null; if (!strstr($subject, "note " . $lastid)) { /* File an error but hold the data in the queue. errorcode GTK_444 */ file_put_contents($stats, "GTK_444: {$lastid} held in queue\n", FILE_APPEND); if (strstr($subject, "note " . $id)) { /* NNTP might have been too fast for us! */ $lastid = $id; $lastemail = $email; $lastpage = $page; $flag = true; } } else { /* If we're working with $lastid, we need to get the data out of the queue db first */ $queuedb = sqlite_open($queuefile); $query = sqlite_unbuffered_query($db, "SELECT * FROM notes WHERE id = {$lastid}", SQLITE_ASSOC, &$errcode); if (!$query || $errcode) { sqlite_close($queuedb); file_put_contents($stats, "{$errcode}:{$lastid} (failed SQL query)\n", FILE_APPEND); } else { $last = sqlite_fetch_array($query, SQLITE_ASSOC); $lastpage = $last['page']; $lastemail = $last['email']; $db_string = '("' . $lastid . '", "' . $lastpage . '", "' . $last['lang'] . '", "' . $last['date'] . '", "' . $lastemail . '", "' . $last['display'] . '", "' . $last['note'] . '")'; sqlite_close($queuedb); $flag = true; } } if ($flag) { $notesdb = sqlite_open($notesfile); $result = sqlite_exec($notesdb, "INSERT INTO notes VALUES {$db_string}");
/** * Executes an unbuffered SQL query * * @param fUnbufferedResult $result The result object for the query * @return void */ private function executeUnbufferedQuery($result) { $old_level = error_reporting(error_reporting() & ~E_WARNING); if ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection, 20)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_unbuffered_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL(), MYSQLI_USE_RESULT)); } elseif ($this->extension == 'oci8') { $oci_statement = oci_parse($this->connection, $result->getSQL()); $result->setResult(oci_execute($oci_statement, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS) ? $oci_statement : FALSE); } elseif ($this->extension == 'odbc') { $result->setResult(odbc_exec($this->connection, $result->getSQL())); } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_unbuffered_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $sqlite_error_message)); } elseif ($this->extension == 'sqlsrv') { $result->setResult(sqlsrv_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'pdo') { $result->setResult($this->connection->query($result->getSQL())); } error_reporting($old_level); if ($this->extension == 'sqlite') { $this->checkForError($result, $sqlite_error_message); } elseif ($this->extension == 'oci8') { $this->checkForError($result, $oci_statement); } else { $this->checkForError($result); } }
function check_if_exists($cc) { $result = sqlite_unbuffered_query("SELECT id FROM country_data WHERE cc_code_2='{$cc}'", sqlite_r); return sqlite_fetch_single($result); }
/** * Submit a SQL query to database * * @param string $query query SQL SQLite compatible * @param bool $buffer true or false (If you only need sequential access to the data, it is recommended false) If you use false, some function do not work. * @access public * @return bool */ function query($query, $buffer = true) { $this->_command = $query; $this->_buffer = $buffer; if ($buffer) { $this->_result = @sqlite_query($query, $this->_conn); } else { $this->_result = @sqlite_unbuffered_query($query, $this->_conn); } if (!$this->_result) { $this->_showError(); return false; } else { //echo $query . '<p>'; return true; } }
function sqlitem_unbuffered_query($dbh, $query) { return sqlite_unbuffered_query($dbh, $query); }
function check_if_exists($cc) { $result = sqlite_unbuffered_query("SELECT id FROM country_data WHERE cc_code_2='{$cc}'", sqlite_r); $data = sqlite_fetch_array($result, SQLITE_NUM); return $data ? $data[0] : NULL; }
public function query($sql) { $this->errString = null; $this->requireConnected(); return sqlite_unbuffered_query($this->oDB, $sql, SQLITE_ASSOC, $this->errString); }
sqlite_rewind($r); while (sqlite_valid($r)) { var_dump(sqlite_current($r, SQLITE_NUM)); sqlite_next($r); } sqlite_exec("DROP TABLE strings", $db); /////// sqlite_query("CREATE TABLE strings(foo VARCHAR, bar VARCHAR, baz VARCHAR)", $db); echo "Buffered\n"; $r = sqlite_query("SELECT * from strings", $db); echo "num fields: " . sqlite_num_fields($r) . "\n"; for ($i = 0; $i < sqlite_num_fields($r); $i++) { var_dump(sqlite_field_name($r, $i)); } echo "Unbuffered\n"; $r = sqlite_unbuffered_query("SELECT * from strings", $db, SQLITE_NUM, $errmsg); if (!$r) { var_dump($errmsg); } echo "num fields: " . sqlite_num_fields($r) . "\n"; for ($i = 0; $i < sqlite_num_fields($r); $i++) { var_dump(sqlite_field_name($r, $i)); } sqlite_exec("DROP TABLE strings", $db); ///// $data = array(array(0 => 'one', 1 => 'two'), array(0 => 'three', 1 => 'four')); sqlite_query("CREATE TABLE strings(a VARCHAR, b VARCHAR)", $db); foreach ($data as $str) { sqlite_query("INSERT INTO strings VALUES('{$str[0]}','{$str[1]}')", $db); } echo "====BUFFERED====\n";
/** * @see Database::sendUnbufferedQuery() */ public function sendUnbufferedQuery($query, $limit = 0, $offset = 0) { $query = $this->handleLimitParameter($query, $limit, $offset); $this->queryCount++; $this->queryID = @sqlite_unbuffered_query($this->linkID, $query); if ($this->queryID === false) { throw new DatabaseException("Invalid SQL: " . $query, $this); } return $this->queryID; }
/** * Executes given SQL statement. * @param string $queryString * @return resource|bool * @throws DriverException */ public function runQuery($queryString) { $this->affectedRows = false; if ($this->dbCharset !== null) { $queryString = iconv($this->charset, $this->dbCharset . '//IGNORE', $queryString); } if ($this->unbuffered) { $result = @sqlite_unbuffered_query($this->resource, $queryString, null, $error); } else { $result = @sqlite_query($this->resource, $queryString, null, $error); } if ($error && $result === false) { throw new DriverException($error, sqlite_last_error($this->resource), $queryString); } $this->affectedRows = @sqlite_changes($this->resource); return $result; }
function write_data($table_name) { global $db; static $proper; if (is_null($proper)) { $proper = version_compare(PHP_VERSION, '5.1.3', '>='); } if ($proper) { $col_types = sqlite_fetch_column_types($db->db_connect_id, $table_name); } else { $sql = "SELECT sql\n\t\t\t\tFROM sqlite_master\n\t\t\t\tWHERE type = 'table'\n\t\t\t\t\tAND name = '" . $table_name . "'"; $table_data = sqlite_single_query($db->db_connect_id, $sql); $table_data = preg_replace('#CREATE\\s+TABLE\\s+"?' . $table_name . '"?#i', '', $table_data); $table_data = trim($table_data); preg_match('#\\((.*)\\)#s', $table_data, $matches); $table_cols = explode(',', trim($matches[1])); foreach ($table_cols as $declaration) { $entities = preg_split('#\\s+#', trim($declaration)); $column_name = preg_replace('/"?([^"]+)"?/', '\\1', $entities[0]); // Hit a primary key, those are not what we need :D if (empty($entities[1]) || strtolower($entities[0]) === 'primary' && strtolower($entities[1]) === 'key') { continue; } $col_types[$column_name] = $entities[1]; } } $sql = "SELECT *\n\t\t\tFROM {$table_name}"; $result = sqlite_unbuffered_query($db->db_connect_id, $sql); $rows = sqlite_fetch_all($result, SQLITE_ASSOC); $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES ('; foreach ($rows as $row) { foreach ($row as $column_name => $column_data) { if (is_null($column_data)) { $row[$column_name] = 'NULL'; } else { if ($column_data == '') { $row[$column_name] = "''"; } else { if (strpos($col_types[$column_name], 'text') !== false || strpos($col_types[$column_name], 'char') !== false || strpos($col_types[$column_name], 'blob') !== false) { $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data)); } } } } $this->flush($sql_insert . implode(', ', $row) . ");\n"); } }
/** * Executes the SQL query. * @param string SQL statement. * @return IDibiResultDriver|NULL * @throws DibiDriverException */ public function query($sql) { if ($this->dbcharset !== NULL) { $sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql); } DibiDriverException::tryError(); if ($this->buffered) { $res = sqlite_query($this->connection, $sql); } else { $res = sqlite_unbuffered_query($this->connection, $sql); } if (DibiDriverException::catchError($msg)) { throw new DibiDriverException($msg, sqlite_last_error($this->connection), $sql); } elseif (is_resource($res)) { return $this->createResultDriver($res); } }
$plik = file('./thesaurus.txt'); $sqlite = sqlite_open('thesaurus.sqlite') or die(sqlite_error_string(sqlite_last_error($sqlite))); sqlite_query($sqlite, 'CREATE TABLE thesaurus (slowo varchar(255), podobne TEXT)') or die(sqlite_error_string(sqlite_last_error($sqlite))); $len = $rows = 0; foreach ($plik as $line) { if (substr($line, 0, 1) == '#') { continue; } $line = explode(';', iconv('ISO-8859-2', 'UTF-8', rtrim($line))); foreach ($line as $words) { $similar = array(); foreach ($line as $word) { if ($word == $words) { continue; } $similar[] = $word; } $similar = implode(', ', $similar); $len = max($len, strlen($words) + strlen($similar) + 1); $rows++; sqlite_query($sqlite, 'INSERT INTO thesaurus (slowo, podobne) VALUES (\'' . funcs::utfToAscii($words) . '\', \'' . $similar . '\')') or die(sqlite_error_string(sqlite_last_error($sqlite))); } } unset($plik); $fp = fopen('thesaurus.res', 'w'); fwrite($fp, $rows . 'x' . $len . "\n"); $data = sqlite_unbuffered_query($sqlite, 'SELECT * FROM thesaurus ORDER BY slowo ASC'); while ($en = sqlite_fetch_array($data, SQLITE_ASSOC)) { fwrite($fp, str_pad($en['slowo'] . ';' . $en['podobne'], $len, "")); } fclose($fp);
/** * Checks whether the log table exists and creates it if necessary. * * @return boolean True on success or false on failure. * @access private */ function _createTable() { $q = "SELECT name FROM sqlite_master WHERE name='" . $this->_table . "' AND type='table'"; $res = sqlite_query($this->_db, $q); if (sqlite_num_rows($res) == 0) { $q = 'CREATE TABLE [' . $this->_table . '] (' . 'id INTEGER PRIMARY KEY NOT NULL, ' . 'logtime NOT NULL, ' . 'ident CHAR(16) NOT NULL, ' . 'priority INT NOT NULL, ' . 'message)'; if (!($res = sqlite_unbuffered_query($this->_db, $q))) { return false; } } return true; }
<?php chdir(dirname(__FILE__)); // pres2 hack $db = sqlite_open("./ip.db"); $res = sqlite_unbuffered_query("SELECT ip_start, ip_end \n\t FROM ip_ranges \n\t WHERE country_code=(SELECT id FROM country_data WHERE country_name='NEW CALEDONIA')", $db); echo '<pre>'; print_r(sqlite_fetch_all($res, SQLITE_ASSOC)); echo '</pre>';
/** * Executes an unbuffered SQL query * * @param string|fStatement $statement The statement to perform * @param fUnbufferedResult $result The result object for the query * @param array $params The parameters for prepared statements * @return void */ private function performUnbufferedQuery($statement, $result, $params) { fCore::startErrorCapture(); $extra = NULL; if (is_object($statement)) { $statement->executeUnbufferedQuery($result, $params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $result->setResult(db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY))); } elseif ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection, 20)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_unbuffered_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL(), MYSQLI_USE_RESULT)); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $result->getSQL()); if (oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { $result->setResult($extra); } else { $result->setResult(FALSE); } } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_unbuffered_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $extra)); } elseif ($this->extension == 'sqlsrv') { $result->setResult(sqlsrv_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'pdo') { $result->setResult($this->connection->query($result->getSQL())); } $this->statement = $statement; $this->handleErrors(fCore::stopErrorCapture()); $this->checkForError($result, $extra); }
/** * Executes an unbuffered SQL query * * @param string|fStatement $statement The statement to perform * @param fUnbufferedResult $result The result object for the query * @param array $params The parameters for prepared statements * @return void */ private function performUnbufferedQuery($statement, $result, $params) { $this->setErrorHandler(); $extra = NULL; if (is_object($statement)) { $statement->executeUnbufferedQuery($result, $params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $result->setResult(db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY))); } elseif ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection, 20)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_unbuffered_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL(), MYSQLI_USE_RESULT)); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $result->getSQL()); if (oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { $result->setResult($extra); } else { $result->setResult(FALSE); } } elseif ($this->extension == 'odbc') { $extra = odbc_exec($this->connection, $result->getSQL()); if ($extra) { odbc_longreadlen($extra, 1048576); odbc_binmode($extra, ODBC_BINMODE_CONVERT); } $result->setResult($extra); } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_unbuffered_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $extra)); } elseif ($this->extension == 'sqlsrv') { $result->setResult(sqlsrv_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'pdo') { $result->setResult($this->connection->query($result->getSQL())); } $this->statement = $statement; $this->restoreErrorHandler(); $this->checkForError($result, $extra); }