Flourish PHP Unframework

fSQLTranslation

class, v1.0.0b20

Takes a subset of SQL from IBM DB2, MySQL, PostgreSQL, Oracle, SQLite and MSSQL and translates into the various dialects allowing for cross-database code

Changes:
1.0.0b20Added fix for PostgreSQL to handle INSERT statements that don't specify any columns or values 9/6/11
1.0.0b19Removed the stray method removeSQLiteIndexes() that was left over from moving code into fSQLSchemaTranslation 5/17/11
1.0.0b18Fixed LENGTH() and SUBSTR() functions for non-ascii characters being stored in MySQL, SQLite and DB2, moved CREATE TABLE support to fSQLSchemaTranslation 5/9/11
1.0.0b17Internal Backwards Compatiblity Break - changed the array keys for translated queries returned from translate() to include a number plus : before the original SQL, preventing duplicate keys 7/14/10
1.0.0b16Added IBM DB2 support 4/13/10
1.0.0b15Fixed a bug with MSSQL national character conversion when running a SQL statement with a sub-select containing joins 12/18/09
1.0.0b14Changed PostgreSQL to cast columns in LOWER() calls to VARCHAR to allow UUID columns (which are treated as a VARCHAR by fSchema) to work with default primary key ordering in fRecordSet 12/16/09
1.0.0b13Added a parameter to enableCaching() to provide a key token that will allow cached values to be shared between multiple databases with the same schema 10/28/09
1.0.0b12Backwards Compatibility Break - Removed date translation functionality, changed the signature of translate(), updated to support quoted identifiers, added support for PostgreSQL, MSSQL and Oracle schemas 10/22/09
1.0.0b11Fixed a bug with translating MSSQL national columns over an ODBC connection 9/18/09
1.0.0b10Changed last bug fix to support PHP 5.1.6 9/18/09
1.0.0b9Fixed another bug with parsing table aliases for MSSQL national columns 9/18/09
1.0.0b8Fixed a bug with parsing table aliases that occurs when handling MSSQL national columns 9/9/09
1.0.0b7Fixed a bug with translating NOT LIKE operators in PostgreSQL 7/15/09
1.0.0b6Changed replacement values in preg_replace() calls to be properly escaped 6/11/09
1.0.0b5Update code to only translate data types inside of CREATE TABLE queries 5/22/09
1.0.0b4Added the missing __get() method for callback support 5/6/09
1.0.0b3Added Oracle and caching support, various bug fixes 5/4/09
1.0.0b2Fixed a notice with SQLite foreign key constraints having no ON clauses 2/21/09
1.0.0bThe initial implementation 9/25/07

Static Methods

::compose() protected

Composes text using fText if loaded

Signature

string compose( string $message, mixed $component [, ... ] )

Parameters

string $message The message to compose
mixed $component [, ... ] A string or number to insert into the message

Returns

The composed and possible translated message

::sqliteCotangent() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; calculates the cotangent of a number

Signature

numeric sqliteCotangent( numeric $x )

Parameters

numeric $x The number to calculate the cotangent of

Returns

The contangent of $x

::sqliteDate() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; returns the current date

Signature

string sqliteDate( )

Returns

The current date

::sqliteLength() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite length function; returns the number of UTF-8 characters in a string

Signature

string sqliteLength( string $string )

Parameters

string $string The string to measure

Returns

The current date

::sqliteLogBaseFirst() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; calculates the log to a specific base of a number

Signature

numeric sqliteLogBaseFirst( integer $base, numeric $num )

Parameters

integer $base The base for the log calculation
numeric $num The number to calculate the logarithm of

Returns

The logarithm of $num to $base

::sqliteSign() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; returns the sign of the number

Signature

numeric sqliteSign( numeric $x )

Parameters

numeric $x The number to change the sign of

Returns

-1 if a negative sign, 0 if zero, 1 if positive sign

::sqliteSubstr() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; creates a substring

Signature

string sqliteSubstr( string $string, integer $start, integer $length )

Parameters

string $string The string to take a substring of
integer $start The one-based position to start the substring at
integer $length The length of the substring to take

Returns

The substring

::sqliteTime() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; returns the current time

Signature

string sqliteTime( )

Returns

The current time

::sqliteTimestamp() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Callback for custom SQLite function; returns the current timestamp

Signature

string sqliteTimestamp( )

Returns

The current date

Methods

->__construct() public

Sets up the class and creates functions for SQLite databases

Signature

fSQLTranslation __construct( fDatabase $database )

Parameters

fDatabase $database The database being translated for

->__get() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

All requests that hit this method should be requests for callbacks

Signature

callback __get( string $method )

Parameters

string $method The method to create a callback for

Returns

The callback for the method requested

->clearCache() public

Clears all of the schema info out of the object and, if set, the fCache object

Signature

void clearCache( )

->enableCaching() public

Sets the schema info to be cached to the fCache object specified

Signature

void enableCaching( fCache $cache, $key_token=NULL )

Parameters

fCache $cache The cache to cache to
$key_token

->enableDebugging() public

Sets if debug messages should be shown

Signature

void enableDebugging( boolean $flag )

Parameters

boolean $flag If debugging messages should be shown

->translate() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Translates Flourish SQL into the dialect for the current database

Signature

array translate( array $statements, array &$rollback_statements=NULL )

Parameters

array $statements The SQL statements to translate
array &$rollback_statements SQL statements to rollback the returned SQL statements if something goes wrong - only applicable for MySQL ALTER TABLE statements

Returns

The translated SQL statements all ready for execution. Statements that have been translated will have string key of the number, : and the original SQL, all other will have a numeric key.