From: Eric F. <wg...@us...> - 2004-08-11 00:16:34
|
Update of /cvsroot/phpliteadmin/phpLiteAdmin/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2876/lib Modified Files: sqlite.php5 Log Message: Added a bunch of functions Index: sqlite.php5 =================================================================== RCS file: /cvsroot/phpliteadmin/phpLiteAdmin/lib/sqlite.php5,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sqlite.php5 4 Aug 2004 01:53:02 -0000 1.1 +++ sqlite.php5 11 Aug 2004 00:16:23 -0000 1.2 @@ -60,19 +60,113 @@ private $var; /** - * Database query - * + * Executes a query and returns the results as an array + * * @param string $query Database query + * @param integer $result_type Type of array data returned + * @param boolean $decode_binary Whether or not to decode binary data */ - function query( $query ) + function array_query( $query, $result_type = SQLITE_ASSOC, $decode_binary = TRUE ) { if( !( $this->connected ) ) { return FALSE; } - return sqlite_query( $this->connection, $query ); + return sqlite_array_query ( $this->connection, $query, $result_type, $decode_binary ); + } + + /** + * Returns the number of rows that were changed by the most recent sql statement + * + * @params resource $result Resource handle from query + */ + + function changes( $result ) + { + return sqlite_changes( $result ); + } + + /** + * Registers a regular function for use in sql queries + * + * @param string $function Name of the function for use in sql queries + * @param string $callback Name of the function + * @param integer $num_args Number of params in the function + */ + + function create_sqlite_function( $function, $callback, $num_args = FALSE ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + if ( $num_args != FALSE ) + { + return sqlite_create_function( $this->connection, $function, $callback, $num_args ); + } + else + { + return sqlite_create_function( $this->connection, $function, $callback ); + } + } + + /** + * Returns a human readable form of a sqlite error code + * + * @params integer $error_code Error code number + */ + + function error_string( $error_code ) + { + return sqlite_error_string( $error_code ); + } + + /** + * Escapes strings for use in a query + * + * @param string $string The string that will be escaped + */ + + function escape_string( $string ) + { + return sqlite_escape_string( $string ); + } + + /** + * Executes a sql query that won't return any results + * + * @param string $query Database query + */ + + function execute( $query ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_exec( $this->connection, $query ); + } + + /** + * Fetch data from database in an array of arrays + * + * @param resource $result Resource handle from query + * @param integer $result_type Type of array data returned + * @param boolean $decode_binary Whether or not to decode binary data + */ + + function fetch_all( $result, $result_type = SQLITE_ASSOC, $decode_binary = TRUE ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_fetch_all( $result, $result_type, $decode_binary ); } /** @@ -94,6 +188,159 @@ } /** + * Gets the columns and their types + * + * @param string $table Table name for the columns + * + */ + + function fetch_column_types( $table ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_fetch_column_types( $this->connection, $table ); + } + + /** + * Fetches the first column of a result + * + * @param resource $result Resource handle from query + * @param integer $result_type Type of array data returned + * @param boolean $decode_binary Whether or not to decode binary data + */ + + function fetch_single( $result, $result_type = SQLITE_ASSOC, $decode_binary = TRUE ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_fetch_single( $result, $result_type, $decode_binary ); + } + + /** + * Returns the name of the given field + * + * @param resource $result Resource handle from query + * @param integer $field_index Number of the field + */ + + function field_name( $result, $field_index ) + { + return sqlite_field_name( $result, $field_index ); + } + + /** + * Returns whether or not more rows are available + * + * @param resource $result Resource handle from query + */ + + function has_more( $result ) + { + return sqlite_has_more( $result ); + } + + /** + * Returns the last error code + */ + + function last_error() + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_last_error( $this->connection ); + } + + /** + * Returns the row id of the most recent inserted row + */ + + function last_insert_rowid() + { + return sqlite_last_insert_rowid( $this->connection ); + } + + /** + * Returns the number of fields + * + * @param resource $result Resource handle from query + */ + + function num_fields( $result ) + { + return sqlite_num_fields( $result ); + } + + /** + * Returns the number of rows + * + * @param resource $result Resource handle from query + */ + + function num_rows( $result ) + { + return sqlite_num_rows( $result ); + } + + /** + * Database query + * + * @param string $query Database query + */ + + function query( $query ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_query( $this->connection, $query ); + } + + /** + * Database query and returns an array either for one column or the first row + * + * @param string $query Database query + * @param boolean $first_row_only Return first row + * @param boolean $decode_binary Whether or not to decode binary data + */ + + function single_query( $query, $first_row_only = FALSE, $decode_binary = TRUE ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_single_query( $this->connection, $first_row_only, $decode_binary ); + } + + /** + * Database query that doesn't buffer all data + * + * @param string $query Database query + */ + + function unbuffered_query( $query ) + { + if( !( $this->connected ) ) + { + return FALSE; + } + + return sqlite_unbuffered_query( $this->connection, $query ); + } + + /** * Destructor */ |