DB_Sqlite_Tools
[ class tree: DB_Sqlite_Tools ] [ index: DB_Sqlite_Tools ] [ all elements ]

Class: DB_Sqlite_Tools

Source Location: /DB_Sqlite_Tools-0.1.7/DB/Sqlite/Tools.php

Class Overview


Class to manage sqlite database. An object-oriented interface to sqlite integrity check, optimizations and backup and export. It curently supports pragma integrity checks, cache values to optimize performance, synchronisation values for an higher integrity protection.


Author(s):

Version:

  • Release: 0.1.7

Copyright:

  • Copyright (c) 2004-2006 David Costa

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 118]
Class to manage sqlite database. An object-oriented interface to sqlite integrity check, optimizations and backup and export. It curently supports pragma integrity checks, cache values to optimize performance, synchronisation values for an higher integrity protection.

For backups it supports ftp, rsync (both local and remote) and local backups.

It offer an extra in build export method to XML for a whole database schema and data which can be particularly useful for backup and export purposes.

Via the XML parser it allows to import and XML dump back to an Sqlite database.



[ Top ]


Class Variables

$database = array()

[line 176]

List of databases.
  • Access: public

Type:   string


[ Top ]

$debug =  false

[line 169]

Debug mode.
  • Access: public

Type:   string


[ Top ]

$email =

[line 178]

  • Access: public

Type:   mixed


[ Top ]

$showLogs =

[line 259]

If true, shows logs as they are added to DB.
  • Access: public

Type:   bool


[ Top ]



Method Detail

cacheSize   [line 366]

true cacheSize( [int $pages = false])

Check or set the cacheSize of the database.

As a default value an sqlite database will hold 2000 disk pages in the memory each page requires approximately 1.5 K of memory. For intensive UPDATE or DELETE queries an higher memory might result in a speed increase. If pages parameter is not defined it will return the current cache size of the database or the multiple databases if $this->database is an array with more then one element

If a valid integer is passed as $pages parameter it will set the cache size for the database or for multiple database if $this->database is an array with more then one element

If defined it will set the new cache size (in pages) as per the specified integer.

Note: When setting a new cache size. It might get a query error if on the database or one of the databases doesn't have the relevant write permissions. Please set the necessary permissions on the database/databases before attemping to change their cache value.

  • Throws: PEAR_Exception
  • Access: public

Parameters:

int   $pages   —  (optional) number of pages to hold in the updated memory allocation

[ Top ]

checkIntegrity   [line 314]

true checkIntegrity( )

Checks the database integrity does an integrity check of the entire

database including malformed records, corrupted pages out of order records, invalid indeces returns okay on success or the error details, if multiple is true the the value for $database in the constructor is expected to be an array with a list of databases.

  • Throws: PEAR_Exception
  • Access: public

[ Top ]

copySafe   [line 517]

void copySafe( [string $path = ''])

Safely duplicates a database file. copySafe should be performed before a backup as transfering via ftp or rsync.

With this function we obtain an exclusive lock on the database before the copy, we then check the integrity of the copied databases. if the integrity check on the copied database returns OK this means that we have a cloned database ready for backup purposes.

Individual or multiple databases are duplicated with the same name of the original database and the suffix .bkp

  • Throws: PEAR_Exception
  • Access: public

Parameters:

string   $path   —  (optional) Destination path, default is current working path.

[ Top ]

createDBFromXML   [line 1084]

void createDBFromXML( string $xmlFile, string $db)

Converts an XML exported database back to an Sqlite database
  • Access: public

Parameters:

string   $xmlFile   —  the XML database dump to convert
string   $db   —  the sqlite db to be generated from the XML data

[ Top ]

createXMLDumps   [line 1045]

true createXMLDumps( [ $path = ''])

For each of the databases in our contructor array creates an XML dump including all the tables of that database.

The XML file is generated via the function performXMLDump The backup file is by default the database name .xml

  • Throws: PEAR exception on failure
  • Access: public

Parameters:

   $path   — 

[ Top ]

dbFileInfo   [line 455]

array dbFileInfo( )

Retrieve general information on the database files like filename, owner id, group, name, permissions, library encoding and version, the size of the database, last time it was modified, blocks and generally every possible information on the database files.
  • Return: An array of databases info.
  • Throws: PEAR_Exception
  • Access: public

[ Top ]

__construct (Constructor)   [line 273]

return __construct( string $database)

Instantiate a new SQLite_Tools Object Expects a db location or an array of db locations for multiple checks
  • Return: array
  • Access: public

Parameters:

string   $database   —  the Sqlite database.

[ Top ]

ftpBackup   [line 613]

true ftpBackup( string $server, string $username, string $password, [string $path = ''])

Safely copy the backup db to a remote ftp server. this function can be called only after a copySafe operation is performed.

It will backup every database in the backup dir which is set with copySafe. If the intended use is to backup different group of databases the user can simply set a different path for copySafe.

  • Throws: PEAR_Exception
  • Access: public

Parameters:

string   $server   —  remote ftp server
string   $username   —  ftp username
string   $password   —  ftp password
string   $path   —  remote ftp path

[ Top ]

localBackup   [line 675]

void localBackup( string $destination)

Creates a local backup of the database file and checks for its integrity.
  • Throws: PEAR_Exception
  • Access: public

Parameters:

string   $destination   —  Local backup path.

[ Top ]

localRsync   [line 725]

void localRsync( string $databasesPath, string $backupsPath, [string $options = '--verbose --stats --recursive --progress --delete'])

Initiaties a local rsync of a given database path requires rsync installed locally.
  • Throws: PEAR_Exception
  • Access: public

Parameters:

string   $databasesPath   —  Path to the databases folder to sync locally
string   $backupsPath   —  Sync Destionation path
string   $options   —  Rsync options

[ Top ]

remoteRsync   [line 760]

void remoteRsync( sting $databasesPath, string $configfile, string $configfilepath, string $uid, string $gid, string $allowedhost, string $logs, string $secretfile)

remoteRsync prepared the server where this package is running to receive read connections over rsync for the purpose of remote synchronisation.

it created a valid rsync configuration file and starts the deamon allowing connection from the allowed host.

This function is experimental.

  • Throws: PEAR_Exception
  • Access: public

Parameters:

sting   $databasesPath   —  Path for the databases folder
string   $configfile   —  name of the rsync config file
string   $configfilepath   —  path where the rsync config file will be saved the users that runs apache must have permissions on this path for the config, the pid and the lock file
string   $uid   —  user id under which rsync will run
string   $gid   —  group id under which rsync will run
string   $allowedhost   —  ip or domain of the allowed host
string   $logs   —  logs file name and path
string   $secretfile   —  rsync secret file location (which should contain the password)

[ Top ]

sqliteLogs   [line 838]

void sqliteLogs( [string $db = ''], [string $maketable = true], [string $table = ''])

Logs all the perfomed action in a database log this includes backups, integrity checks each of the integrity queries. Verbose XML style output for each of the actions.

Sample log output - <logevent> <class>DB_Sqlite_Tools</class> <function>cacheSize</function> <data> 'cache correctly reset to 10000' </data> </logevent>

All the logs are saved with the time of execution. The user can easily generate customized logs from the raw data provided in this package.

  • Throws: PEAR_Exception on failure
  • Access: public

Parameters:

string   $db   —  Logs database
string   $maketable   —  create a default log table
string   $table   —  table name

[ Top ]

sync   [line 417]

true sync( [sting $value = false])

Check or set the synchronous value for the database.

Sqlite provides with different synchronous modes. The synchronous level determines the integrity protection. At NORMAL (default mode) the sqlite engine will stop at most critical moment providing with a limited integrity protection of the database. In FULL mode the engine will stop more often thus ensuring and higher integrity level. When OFF the engine will continue as soon as the new data is provided without stopping. Values are represented by an integer, 1 for NORMAL, 2 for FULL and 0 for off.

If the parameter value is not set it will return the current default syncronous for the databases. If value is set with either FULL, NORMAL or OFF it will change the default syncronous value for each of the databases.

  • Throws: PEAR_Exception
  • Access: public

Parameters:

sting   $value   —  (optional) A synchronous value.

[ Top ]

XMLDecode   [line 947]

string XMLDecode( string $str)

Decodes the XML content.
  • Access: public

Parameters:

string   $str   —  A content.

[ Top ]

XMLEncode   [line 962]

string XMLEncode( string $str)

Encodes the XML content.
  • Access: public

Parameters:

string   $str   —  A content.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:39:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.