Sqlite3Manager
extends PdoManager
in package
SQLite3 DatasourceManager
This is concrete class, implementing the abstract class DatasourceManager for the Sqlite3 DBMS (file format not compatible with versions less than 3). Method explanations are from the parent class.
Tags
Table of Contents
- MAX_CONNECTIONS = 20
- Maximum number of connections to cache
- $active_connections : array<string|int, mixed>
- Arrays used to manage dbms connections which have been made so they can be recycled
- $connect_string : string
- String containing host info etc that was used to establish a DB connection
- $connect_time : int
- The time at which the last attempt to connect to the database was made
- $db_host : string
- The hostname of where the database is located
- $db_name : string
- The name of the database on host we are connecting to
- $db_password : string
- The password of the user to connect the dbms as
- $db_user : string
- The user to connect to dbms as
- $num_affected : int
- The number of rows affected by the last exec
- $pdo : resource
- Used to hold the PDO database object
- $pdo_flag : bool
- Whether a PDO driver or the Sqlite3 driver is used to make the connection
- $query_log : string
- Used to store statistics about what queries have been run depending on the debug level
- $to_upper_dbms : mixed
- If DBMS is one like postgres which lower cases table names that aren't in quotes that this field has the name of the database; otherwise, false.
- $total_time : int
- Used to store the total time taken to execute queries
- __construct() : mixed
- {@inheritDoc}
- affectedRows() : int
- Returns the number of rows affected by the last sql statement
- autoIncrement() : string
- Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).
- beginTransaction() : mixed
- blobType() : string
- Used when creating databases to set what a blob is If the DBMS is Postgres, there is not BLOB type, only BYTEA
- closeCursor() : mixed
- commit() : mixed
- connect() : mixed
- Select file name of database.
- copyRecursive() : mixed
- Recursively copies a source directory to a destination directory
- copyTable() : mixed
- Copies the contents of from_table in the first database into the to a to_table of suitable schema in a second database. It assumes the table exists in both databases, both have the same number of columns, etc.
- disconnect() : mixed
- Closes connections to DBMS
- escapeString() : string
- Used to escape strings before insertion in the database to avoid SQL injection
- exec() : mixed
- Hook Method for execute(). Executes the sql command on the database
- execute() : mixed
- Executes the supplied sql command on the database, depending on debug levels computes query statistics
- fetchArray() : array<string|int, mixed>
- Returns the next row from the provided result set
- fileInfoRecursive() : array<string|int, mixed>
- Returns arrays of filesizes and file modifications times of files in a directory
- insertID() : string
- Returns the ID generated by the last insert statement if table has an auto increment key column
- insertIgnore() : string
- Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored
- integerType() : string
- Used when creating databases to set what an integer is If the DBMS is sqlite, there is not BIGINT type, only INTEGER which can be 8 bytes
- limitOffset() : string
- How a daabase can perform LIMIT OFFSET queries is not standardized between DBMS's. This method take a $start, a $num, and a $dbinfo and returns the string that would restrict a query to show $num many rows starting at $start. In the case that $num is not provided then it returns the string represent returning the first $start many rows. In the case that $dbinfo is not provided the current Yioop default database is used.
- pageType() : string
- Used when creating databases to set what type should be used for wiki pages
- serialType() : string
- Used to return the database column type for a column that can be used to do autoincrementing. Usually this will just be INTEGER, however, for Postgres is SERIAL.
- setWorldPermissionsRecursive() : mixed
- Recursively chmod a directory to 0777
- traverseDirectory() : array<string|int, mixed>
- Recursively traverse a directory structure and call a callback function
- unlinkRecursive() : mixed
- Recursively delete a file or directory
- updateConnectionCache() : mixed
- Caches current PDO connection. If cache full evicts last
Constants
MAX_CONNECTIONS
Maximum number of connections to cache
public
int
MAX_CONNECTIONS
= 20
Properties
$active_connections
Arrays used to manage dbms connections which have been made so they can be recycled
public
static array<string|int, mixed>
$active_connections
= []
$connect_string
String containing host info etc that was used to establish a DB connection
public
string
$connect_string
= ""
$connect_time
The time at which the last attempt to connect to the database was made
public
int
$connect_time
= 0
$db_host
The hostname of where the database is located
public
string
$db_host
= ""
$db_name
The name of the database on host we are connecting to
public
string
$db_name
= ""
$db_password
The password of the user to connect the dbms as
public
string
$db_password
= ""
$db_user
The user to connect to dbms as
public
string
$db_user
= ""
$num_affected
The number of rows affected by the last exec
public
int
$num_affected
= 0
$pdo
Used to hold the PDO database object
public
resource
$pdo
= null
$pdo_flag
Whether a PDO driver or the Sqlite3 driver is used to make the connection
public
bool
$pdo_flag
$query_log
Used to store statistics about what queries have been run depending on the debug level
public
string
$query_log
$to_upper_dbms
If DBMS is one like postgres which lower cases table names that aren't in quotes that this field has the name of the database; otherwise, false.
public
mixed
$to_upper_dbms
$total_time
Used to store the total time taken to execute queries
public
int
$total_time
Methods
__construct()
{@inheritDoc}
public
__construct() : mixed
Return values
mixed —affectedRows()
Returns the number of rows affected by the last sql statement
public
abstract affectedRows() : int
Return values
int —the number of rows affected by the last insert, update, delete
autoIncrement()
Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).
public
autoIncrement(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
contains strings DBMS, DB_HOST, DB_USER, DB_PASSWORD
Return values
string —to achieve auto_increment function for the given DBMS
beginTransaction()
public
abstract beginTransaction() : mixed
Return values
mixed —blobType()
Used when creating databases to set what a blob is If the DBMS is Postgres, there is not BLOB type, only BYTEA
public
blobType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to a BLOB
closeCursor()
public
abstract closeCursor(mixed $result) : mixed
Parameters
- $result : mixed
Return values
mixed —commit()
public
abstract commit() : mixed
Return values
mixed —connect()
Select file name of database.
public
connect([string $db_host = CDB_HOST ][, string $db_user = CDB_USER ][, string $db_password = CDB_PASSWORD ][, string $db_name = CDB_NAME ]) : mixed
Parameters
- $db_host : string = CDB_HOST
-
not used but in base constructor
- $db_user : string = CDB_USER
-
not used but in base constructor
- $db_password : string = CDB_PASSWORD
-
not used but in base constructor
- $db_name : string = CDB_NAME
-
filename of sqlite database. If the name does not contain any "/" symbols assume it is in the crawl directory data folder and we don't have a file extension; otherwise assume the name is a complete filepath
Return values
mixed —return false if not successful and some kind of connection object/identifier otherwise
copyRecursive()
Recursively copies a source directory to a destination directory
public
copyRecursive(string $source_dir, string $destination_dir) : mixed
It would have been cool to use traverseDirectory to implement this, but it was a little bit too much of a stretch to shoehorn the code to match
Parameters
- $source_dir : string
-
the name of the source directory
- $destination_dir : string
-
the name of the destination directory
Return values
mixed —copyTable()
Copies the contents of from_table in the first database into the to a to_table of suitable schema in a second database. It assumes the table exists in both databases, both have the same number of columns, etc.
public
static copyTable(string $from_table, resource $from_dbm, resource $to_table, resource $to_dbm) : mixed
Parameters
- $from_table : string
-
name of the table to be copied from
- $from_dbm : resource
-
database resource for the from table
- $to_table : resource
-
name of the table to be copied to
- $to_dbm : resource
-
database resource for the to table
Return values
mixed —disconnect()
Closes connections to DBMS
public
abstract disconnect() : mixed
Return values
mixed —escapeString()
Used to escape strings before insertion in the database to avoid SQL injection
public
abstract escapeString(string $str) : string
Parameters
- $str : string
-
string to escape
Return values
string —a string which is safe to insert into the db
exec()
Hook Method for execute(). Executes the sql command on the database
public
abstract exec(string $sql[, array<string|int, mixed> $params = [] ]) : mixed
This method operates on either query or data manipulation statements
Parameters
- $sql : string
-
SQL statement to execute
- $params : array<string|int, mixed> = []
-
bind_name => value values to interpolate into the $sql to be executes
Return values
mixed —false if query fails, resource or true otherwise
execute()
Executes the supplied sql command on the database, depending on debug levels computes query statistics
public
execute(string $sql[, array<string|int, mixed> $params = [] ]) : mixed
This method operates either query or data manipulation statements
Parameters
- $sql : string
-
SQL statement to execute
- $params : array<string|int, mixed> = []
-
bind_name => value values to interpolate into the $sql to be executes
Return values
mixed —false if query fails, resource or true otherwise
fetchArray()
Returns the next row from the provided result set
public
abstract fetchArray(resource $result) : array<string|int, mixed>
Parameters
- $result : resource
-
result set reference of a query
Return values
array<string|int, mixed> —the next row from the result set as an associative array in the form column_name => value
fileInfoRecursive()
Returns arrays of filesizes and file modifications times of files in a directory
public
fileInfoRecursive(string $dir[, bool $root_too = true ]) : array<string|int, mixed>
Parameters
- $dir : string
-
directory to get filesizes for
- $root_too : bool = true
-
whether to have an entry for the whole directory too
Return values
array<string|int, mixed> —of fileinfo information for each file in the folder in question
insertID()
Returns the ID generated by the last insert statement if table has an auto increment key column
public
abstract insertID([string $table_name = "" ]) : string
Parameters
- $table_name : string = ""
-
of table of last insert
Return values
string —the ID of the insert
insertIgnore()
Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored
public
insertIgnore(mixed $sql[, array<string|int, mixed> $dbinfo = null ]) : string
Parameters
- $sql : mixed
- $dbinfo : array<string|int, mixed> = null
-
containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)
Return values
string —what to use for insert ignore expression
integerType()
Used when creating databases to set what an integer is If the DBMS is sqlite, there is not BIGINT type, only INTEGER which can be 8 bytes
public
integerType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to an 64bit int
limitOffset()
How a daabase can perform LIMIT OFFSET queries is not standardized between DBMS's. This method take a $start, a $num, and a $dbinfo and returns the string that would restrict a query to show $num many rows starting at $start. In the case that $num is not provided then it returns the string represent returning the first $start many rows. In the case that $dbinfo is not provided the current Yioop default database is used.
public
limitOffset(int $start[, int $num = -1 ][, array<string|int, mixed> $dbinfo = null ]) : string
Parameters
- $start : int
-
starting row to return from if ($num == -1, i.e., not supplied in the call) then this is is the number of rows desired
- $num : int = -1
-
number of rows to return
- $dbinfo : array<string|int, mixed> = null
-
containing fields for how to connect to a database
Return values
string —what to use for for LIMIT OFFSET query with input $limit and $num for the DBMS in question
pageType()
Used when creating databases to set what type should be used for wiki pages
public
pageType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to wiki page
serialType()
Used to return the database column type for a column that can be used to do autoincrementing. Usually this will just be INTEGER, however, for Postgres is SERIAL.
public
serialType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)
Return values
string —what to use for serial data type
setWorldPermissionsRecursive()
Recursively chmod a directory to 0777
public
setWorldPermissionsRecursive(string $dir[, bool $chmod_root_too = true ]) : mixed
Parameters
- $dir : string
-
Directory name
- $chmod_root_too : bool = true
-
chmod specified top-level directory as well
Return values
mixed —traverseDirectory()
Recursively traverse a directory structure and call a callback function
public
traverseDirectory(string $dir, function $callback[, bool $root_too = true ]) : array<string|int, mixed>
Parameters
- $dir : string
-
Directory name
- $callback : function
-
Function to call as traverse structure
- $root_too : bool = true
-
whether to have an apply the callback to the whole directory as well
Return values
array<string|int, mixed> —results computed by performing the traversal
unlinkRecursive()
Recursively delete a file or directory
public
unlinkRecursive(string $dir[, bool $delete_root_too = true ]) : mixed
Parameters
- $dir : string
-
file or directory name
- $delete_root_too : bool = true
-
Delete specified top directory as well
Return values
mixed —updateConnectionCache()
Caches current PDO connection. If cache full evicts last
public
updateConnectionCache() : mixed