SQLiteAdmin - Class implementation
This class is a wrapper for the new SQLite extension of PHP5. It's an OOP environment designed for easier Usage of SQLite. This class is designed for and tested with SQLite Version 2.8.14. There is no guarantee that it will run with any other SQLite Version, although it will work most likely with versions prior to 2.8.14. As SQLite itself, this is only a testing stage and there is no guarantee for complete work.
The SQLite Project itself could be called a 'front-end' to this class, since it simply passes all tasks to it.
You can use SQLiteAdmin by spawning this class:
$sqlite = new SQLiteAdmin('filename.db');See the descriptions of the class members and methods for further information.
Located in /sqlite_admin/includes/SQLiteAdmin.class.php (line 72)
Database filename
This stores the complete path and file name of the opened database file, encoded by PHP's base64_encode public function. That is primarily for correct filename passing via HTTP. If this is empty, no database has (yet) been opened.
SQL Constraints array
List of accepted constraints. Used by getTableInfo.
SQL Datatype array
List of accepted data types. Used by getTableInfo.
Database filename
This stores the complete path and file name of the opened database file. If this is empty, no database has (yet) been opened.
Message buffer
This stores all messages produced during processes done by this class. Mostly in cases of error, this string will contain a more accurate description of what went wrong.
Database short filename
This stores the file name without path of the opened database file. If this is empty, no database has (yet) been opened.
Internal database resource
The internally stored database handle. It is set by openDB or createDB and used by most of the public functions. You do not have to take care of this.
Internal result resource
The internally stored result resource. It can be an SQLite query resource or a boolean value depending on the kind of query (whether or not 'SELECT'). It is set whenever the query public function is called with the parameter '$remember' set to true.
Initializes a SQLiteAdmin instance
This initializes an SQLiteAdmin instance. If $filename is not empty, the object try to open (see openDB) the database file and establish a connection to it.
Additionally, it sets up two internal data arrays for keyword lists in the later Table structure parser. These can be given by parameter, too.
Close currently opened database
This will close the currently opened database connection. In any normal case, this will be done at the end of your script automatically. You will need this only if you want to open another database with the same SQLiteAdmin instance.
Create a new database file
This will try to create a new database file. In addition, if it succeeds it will setup the internal $_dblink and create the specific filename strings. If if a table name is passed, it will automatically try to create a new table using tableCreate.
Create an Index
This will create the Index named $name on the table $table in the currently opened database. It will be of the type $type and affect the fields $fields.
Create a new VIEW
This will create a new VIEW named $name with the SELECT statement $sql in the currently opened database.
Delete an Index
This will delete the Index named $name in the currently opened database.
Delete a VIEW
This will delete the VIEW named $name in the currently opened database.
Fetch a result array
This will perform a FetchArray operation using the given data. If $res is NULL, the internal $_result resource will be used. In any other case $res will be treated as result resource. $type is the kind of array that shoud be returned. Will return false if for whatever reason no result row can be fetched.
Get Index information
This will return an array of information of all indices on the table $tablename in the currently opened database.
The returned array contains the following information. (Excerpt of one element):
array {
["name"] => Index name
["rootpage"] => Index rootpage
["sql"] => Complete SQL string that has been used for creating
the Index
["type"] => Index type ('STANDARD' or 'UNIQUE')
["columns"] => Linear array of names of affected columns
["columns_string"] => Comma-seperated list of names of affected columns
}
Get table information
This will return an array of information of all tables in the currently opened database. If $tablename is given the information will be limited to this specific table.
The returned array contains the following information. (Excerpt of one element):
array {
["name"] => Table name
["entries"] => Number of entries in that table
["fields"] => Array containing field data
array {
[linear_index]=>
array {
["field_name"] => Field name
["field_type"] => Field type
["field_keys"] => Field constraints
["field_size"] => Field size
}
}
}
Get a valid content string
Returns a valid content string created from given content string. Some strings are key contents (like NULL) in SQLite. They must not be set in single quotes. All others have to. That is what this public function takes care of. Mostly for internal use.
Get VIEW information
This will return an array of information of all VIEWs in the currently opened database.
The returned array contains the following information. (Excerpt of one element):
array {
["name"] => VIEW name
["rootpage"] => VIEW rootpage
["sql"] => Complete SQL string that has been used for creating
the VIEW
["sql_short"] => The SELECT statement the VIEW represents
["table"] => Name of the table the VIEW uses
}
Check if result exists
This returns true if there is currently a valid $_result resource that can be used for fetchArray() operations.
Check if table exists
Returns true, if the given table exists in currently opened database, or false in any other case.
Get last error
This will return an error message string of the last error that occured during an SQLite operation. It will return an sprintfed string (error number is first and message is second parameter).
Last inserted row id
Returns the row id created by the last insert instruction.
Get number of rows in current result set
Returns the number of rows in the given result set. If $result is NULL, the internal result resource link will be used.
Open an existing database file
This will try to open the given database file. In addition, if it succeeds it will setup the internal $_dblink and create the specific filename strings.
Execute an SQL Query
This will execute an SQL query using the internal database link. $remember decides whether or not an result resource of a SELECT query shall be stored in the internal $_result resource. If that's the case, you can call fetchArray without any other parameters.
Handle ALTER TABLE queries
This is a wrapper function for ALTER TABLE queries, since SQLite does not provide that functionality by itself. It merely parses the given query string and provides the collected data to the internal functions tableAddField(), tableEditField() and tableDeleteField.
Performs a query using a format string and a list of arguments.
This will perform a query using the given format string and the list of arguments passed. It works similar to the php printf function. If the first parameter after the format string is boolean it will be taken as the $remember parameter (see query()) and the other parameters as list. In any other case, all parameters after the format string will be taken for the parameter list.
Example:
// without 'remember':
$res = $cfg_sql->queryFormatted('SELECT * FROM %s WHERE 1', false, 'table');
$row = $cfg_sql->fetchArray($res);
// with 'remember':
$cfg_sql->queryFormatted('SELECT * FROM %s WHERE 1', 'table');
$row = $cfg_sql->fetchArray();
Reset internal result resource
This will reset the internal $_result resource, so that it can be freely used again for further operations.
Add a field to a table.
This will add the field $fldname to the table $tblname. Specifications of the new field are passed. (See parameter list)
WARNING: This public function should be considered instable. Since there are no builtin public functions for table altering in SQLite, we have to do a quite bad workaround by backing all data up, deleting the table and recreating it, then putting all the data back. There has not yet been very intensive testing as this is only a side project of Crafty.
Create new table
This will try to create a new table with the name $tablename in the currently opened database. It will return true if it succeeds, false if fails. It will automatically create an 'id INTEGER PRIMARY KEY' field.
Delete table
This will try to delete the table with the name $tablename in the currently opened database. It will return true if it succeeds, false if fails.
Delete a field from a table.
This will delete the field $fldname from the table $tblname.
WARNING: This public function should be considered instable. Since there are no builtin public functions for table altering in SQLite, we have to do a quite bad workaround by backing all data up, deleting the table and recreating it, then putting all the data back. There has not yet been very intensive testing as this is only a side project of Crafty.
Alter a field of a table.
This will alter the field $fldname in the table $tblname. Specifications of the field are passed. (See parameter list)
WARNING: This public function should be considered instable. Since there are no builtin public functions for table altering in SQLite, we have to do a quite bad workaround by backing all data up, deleting the table and recreating it, then putting all the data back. There has not yet been very intensive testing as this is only a side project of Crafty.
Rename a table.
This will rename $tblname to $tblnewname.
WARNING: This public function should be considered instable. Since there are no builtin public functions for table altering in SQLite, we have to do a quite bad workaround by backing all data up, deleting the table and recreating it, then putting all the data back. There has not yet been very intensive testing as this is only a side project of Crafty.
Documentation generated on Sat, 19 Feb 2005 01:43:59 +0100 by phpDocumentor 1.3.0RC3