\seekquarry\yioop\models\datasourcesSqlite3Manager

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.

Summary

Methods
Properties
Constants
connect()
disconnect()
exec()
affectedRows()
insertID()
fetchArray()
escapeString()
__construct()
execute()
unlinkRecursive()
setWorldPermissionsRecursive()
fileInfoRecursive()
copyRecursive()
traverseDirectory()
autoIncrement()
serialType()
integerType()
insertIgnore()
limitOffset()
copyTable()
$connect_string
$connect_time
$db_host
$db_user
$db_password
$db_name
$pdo
$num_affected
$to_upper_dbms
$active_connections
$query_log
$total_time
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$connect_string

$connect_string : string

String containing host info etc that was used to establish a DB connection

Type

string

$connect_time

$connect_time : string

The time at which the last attempt to connect to the database was made

Type

string

$db_host

$db_host : string

The hostname of where the database is located

Type

string

$db_user

$db_user : string

The user to connect to dbms as

Type

string

$db_password

$db_password : string

The password of the user to connect the dbms as

Type

string

$db_name

$db_name : string

The name of the database on host we are connecting to

Type

string

$pdo

$pdo : resource

Used to hold the PDO database object

Type

resource

$num_affected

$num_affected : integer

The number of rows affected by the last exec

Type

integer

$to_upper_dbms

$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.

Type

mixed

$active_connections

$active_connections : array

Arrays used to manage dbms connections which have been made so they can be recycled

Type

array

$query_log

$query_log : string

Used to store statistics about what queries have been run depending on the debug level

Type

string

$total_time

$total_time : integer

Used to store the total time taken to execute queries

Type

integer

Methods

connect()

connect(string  $db_host = \seekquarry\yioop\configs\DB_HOST, string  $db_user = \seekquarry\yioop\configs\DB_USER, string  $db_password = \seekquarry\yioop\configs\DB_PASSWORD, string  $db_name = \seekquarry\yioop\configs\DB_NAME) : mixed

Select file name of database.

Parameters

string $db_host

not used but in base constructor

string $db_user

not used but in base constructor

string $db_password

not used but in base constructor

string $db_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

Returns

mixed —

return false if not successful and some kind of connection object/identifier otherwise

disconnect()

disconnect() 

Closes connections to DBMS

exec()

exec(string  $sql, array  $params = array()) : mixed

Hook Method for execute(). Executes the sql command on the database

This method operates on either query or data manipulation statements

Parameters

string $sql

SQL statement to execute

array $params

bind_name => value values to interpolate into the $sql to be executes

Returns

mixed —

false if query fails, resource or true otherwise

affectedRows()

affectedRows() : integer

Returns the number of rows affected by the last sql statement

Returns

integer —

the number of rows affected by the last insert, update, delete

insertID()

insertID(string  $table_name = "") : string

Returns the ID generated by the last insert statement if table has an auto increment key column

Parameters

string $table_name

of table of last insert

Returns

string —

the ID of the insert

fetchArray()

fetchArray(resource  $result) : array

Returns the next row from the provided result set

Parameters

resource $result

result set reference of a query

Returns

array —

the next row from the result set as an associative array in the form column_name => value

escapeString()

escapeString(string  $str) : string

Used to escape strings before insertion in the database to avoid SQL injection

Parameters

string $str

string to escape

Returns

string —

a string which is safe to insert into the db

__construct()

__construct() 

{@inheritDoc}

execute()

execute(string  $sql, array  $params = array()) : mixed

Executes the supplied sql command on the database, depending on debug levels computes query statistics

This method operates either query or data manipulation statements

Parameters

string $sql

SQL statement to execute

array $params

bind_name => value values to interpolate into the $sql to be executes

Returns

mixed —

false if query fails, resource or true otherwise

unlinkRecursive()

unlinkRecursive(string  $dir, boolean  $deleteRootToo = true) 

Recursively delete a directory

Parameters

string $dir

Directory name

boolean $deleteRootToo

Delete specified top directory as well

setWorldPermissionsRecursive()

setWorldPermissionsRecursive(string  $dir, boolean  $chmodRootToo = true) 

Recursively chmod a directory to 0777

Parameters

string $dir

Directory name

boolean $chmodRootToo

chmod specified top-level directory as well

fileInfoRecursive()

fileInfoRecursive(string  $dir, boolean  $rootToo = true) : array

Returns arrays of filesizes and file modifcations times of files in a directory

Parameters

string $dir

directory to get filesizes for

boolean $rootToo

whether to have an entry for the whole directory too

Returns

array —

of fileinfo information for each file in the folder in question

copyRecursive()

copyRecursive(string  $source_dir, string  $destination_dir) 

Recursively copies a source directory to a destination directory

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

string $source_dir

the name of the source directory

string $destination_dir

the name of the destination directory

traverseDirectory()

traverseDirectory(string  $dir, \seekquarry\yioop\models\datasources\function  $callback, boolean  $rootToo = true) : array

Recursively traverse a directory structure and call a callback function

Parameters

string $dir

Directory name

\seekquarry\yioop\models\datasources\function $callback

Function to call as traverse structure

boolean $rootToo

whether to have an apply the callback to the whole directory as well

Returns

array —

results computed by performing the traversal

autoIncrement()

autoIncrement(array  $dbinfo) : string

Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).

Parameters

array $dbinfo

contains strings DBMS, DB_HOST, DB_USER, DB_PASSWORD

Returns

string —

to achieve auto_increment function for the given DBMS

serialType()

serialType(array  $dbinfo) : 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.

Parameters

array $dbinfo

containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)

Returns

string —

what to use for serial data type

integerType()

integerType(array  $dbinfo) : 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

Parameters

array $dbinfo

containing fields for the current DBMS

Returns

string —

to use for column type corresponding to an 64bit int

insertIgnore()

insertIgnore(  $sql, array  $dbinfo) : string

Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored

Parameters

$sql
array $dbinfo

containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)

Returns

string —

what to use for insert ignore expression

limitOffset()

limitOffset(integer  $start, integer  $num = -1, array  $dbinfo = null) : 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.

Parameters

integer $start

starting row to return from if ($num == -1, i.e., not supplied in the call) then this is is the number of rows desired

integer $num

number of rows to return

array $dbinfo

containing fields for how to connect to a database

Returns

string —

what to use for for LIMIT OFFSET query with input $limit and $num for the DBMS in question

copyTable()

copyTable(string  $from_table, resource  $from_dbm, resource  $to_table, resource  $to_dbm) 

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.

Parameters

string $from_table

name of the table to be copied from

resource $from_dbm

database resource for the from table

resource $to_table

name of the table to be copied to

resource $to_dbm

database resource for the to table