Andrew's Web Libraries (AWL)
AwlDBDialect Class Reference
Inheritance diagram for AwlDBDialect:

Public Member Functions

 __construct ( $connection_string, $dbuser=null, $dbpass=null, $options=null)
 
 SetSearchPath ( $search_path=null)
 
 GetVersion ()
 
 GetFields ( $tablename_string)
 
 TranslateSQL ( $sql_string)
 
 Quote ( $value, $value_type=null)
 
 ReplaceParameters ()
 
 ReplaceNamedParameters ()
 

Public Attributes

const HttpDateFormat = "'Dy, DD Mon IYYY HH24:MI:SS \"GMT\"'"
 
const SqlDateFormat = "'YYYYMMDD\"T\"HH24MISS'"
 
const SqlUTCFormat = "'YYYYMMDD\"T\"HH24MISS\"Z\"'"
 
const SqlDurationFormat = "'\"PT\"HH24\"H\"MI\"M\"'"
 

Protected Attributes

 $dialect
 
 $db
 

Private Attributes

 $version
 

Detailed Description

Definition at line 33 of file AwlDBDialect.php.

Constructor & Destructor Documentation

◆ __construct()

AwlDBDialect::__construct (   $connection_string,
  $dbuser = null,
  $dbpass = null,
  $options = null 
)

Parses the connection string to ascertain the database dialect. Returns true if the dialect is supported and fails if the dialect is not supported. All code to support any given database should be within in an external include.

The database will be opened.

Parameters
string$connection_stringThe PDO connection string, in all it's glory
string$dbuserThe database username to connect as
string$dbpassThe database password to connect with
array$optionsAn array of driver options

Definition at line 90 of file AwlDBDialect.php.

Member Function Documentation

◆ GetFields()

AwlDBDialect::GetFields (   $tablename_string)

Returns the SQL for the current database dialect which will return a two-column resultset containing a list of fields and their associated data types.

Parameters
string$tablename_stringThe name of the table we want fields from

Definition at line 161 of file AwlDBDialect.php.

◆ GetVersion()

AwlDBDialect::GetVersion ( )

Sets the current search path for the database.

Parameters
handle$pdoA handle to an opened database

Definition at line 132 of file AwlDBDialect.php.

◆ Quote()

AwlDBDialect::Quote (   $value,
  $value_type = null 
)

Returns $value escaped in an appropriate way for this database dialect.

Parameters
mixed$valueThe value to be escaped
string$value_typeThe type of escaping desired. If blank this will be worked out from the type of the $value. The special type of 'identifier' can also be used for escaping of SQL identifiers.

@TODO: Someone should confirm this is correct for MySql

PDO handling of \ seems unreliable. We can't use $$string$$ syntax because it also doesn't work. We need to replace ':' so no other named parameters accidentally rewrite the content inside this string(!), and since we're using ' to delimit the string we need SQL92-compliant '' to replace it.

PostgreSQL wants to know when a string might contain escapes, and if this happens old versions of PHP::PDO need the ? escaped as well...

Definition at line 214 of file AwlDBDialect.php.

◆ ReplaceNamedParameters()

AwlDBDialect::ReplaceNamedParameters ( )

Replaces named query parameters of the form :name with appropriately escaped substitutions.

The function takes a variable number of arguments, the first is the SQL string, with replaceable ':name' characters (a la DBI). The subsequent parameters being the values to replace into the SQL string.

The values passed to the routine are analyzed for type, and quoted if they appear to need quoting. This can go wrong for (e.g.) NULL or other special SQL values which are not straightforwardly identifiable as needing quoting (or not).

Parameters
stringThe query string with replacable ':name' identifiers
mixedA ':name' => 'value' hash of values to replace into the SQL string.
Returns
The built query string

If the first argument is an array we treat that as our arguments instead

Definition at line 372 of file AwlDBDialect.php.

◆ ReplaceParameters()

AwlDBDialect::ReplaceParameters ( )

Replaces query parameters with appropriately escaped substitutions.

The function takes a variable number of arguments, the first is the SQL string, with replaceable '?' characters (a la DBI). The subsequent parameters being the values to replace into the SQL string.

The values passed to the routine are analyzed for type, and quoted if they appear to need quoting. This can go wrong for (e.g.) NULL or other special SQL values which are not straightforwardly identifiable as needing quoting (or not). In such cases the parameter can be forced to be inserted unquoted by passing it as "array( 'plain' => $param )".

Parameters
stringThe query string with replacable '?' characters.
mixedThe values to replace into the SQL string.
Returns
The built query string

If the first argument is an array we treat that as our arguments instead

We only split into a maximum of $argc chunks. Any leftover ? will remain in the string and may be replaced at Exec rather than Prepare. Scary!

Definition at line 316 of file AwlDBDialect.php.

◆ SetSearchPath()

AwlDBDialect::SetSearchPath (   $search_path = null)

Sets the current search path for the database.

Definition at line 113 of file AwlDBDialect.php.

◆ TranslateSQL()

AwlDBDialect::TranslateSQL (   $sql_string)

Translates the given SQL string into a form that will hopefully work for this database dialect. This hook is intended to be used by developers to provide support for differences in database operation by translating the query string in an arbitrary way, such as through a file or database lookup.

The actual translation to other SQL dialects will be application-specific, so that any routines called by this will be external to this library, or will use resources loaded from some source external to this library.

The application developer is expected to use this functionality to solve harder translation problems, but is less likely to call this directly, hopefully switching ->Prepare to ->PrepareTranslated in those cases, and then adding that statement to whatever SQL translation infrastructure is in place.

Definition at line 200 of file AwlDBDialect.php.

Member Data Documentation

◆ $db

AwlDBDialect::$db
protected

Holds the PDO database connection

Definition at line 46 of file AwlDBDialect.php.

◆ $dialect

AwlDBDialect::$dialect
protected

#+ @access private Holds the name of the database dialect

Definition at line 41 of file AwlDBDialect.php.

◆ $version

AwlDBDialect::$version
private

Holds the version

Definition at line 51 of file AwlDBDialect.php.

◆ HttpDateFormat

const AwlDBDialect::HttpDateFormat = "'Dy, DD Mon IYYY HH24:MI:SS \"GMT\"'"

#- A PostgreSQL Date Format string suitable for returning HTTP (RFC2068) dates Preferred is "Sun, 06 Nov 1994 08:49:37 GMT" so we do that.

Definition at line 59 of file AwlDBDialect.php.

◆ SqlDateFormat

const AwlDBDialect::SqlDateFormat = "'YYYYMMDD\"T\"HH24MISS'"

A PostgreSQL Date Format string suitable for returning iCal dates

Definition at line 64 of file AwlDBDialect.php.

◆ SqlDurationFormat

const AwlDBDialect::SqlDurationFormat = "'\"PT\"HH24\"H\"MI\"M\"'"

A PostgreSQL Date Format string suitable for returning iCal durations

  • this doesn't work for negative intervals, but events should not have such!

Definition at line 76 of file AwlDBDialect.php.

◆ SqlUTCFormat

const AwlDBDialect::SqlUTCFormat = "'YYYYMMDD\"T\"HH24MISS\"Z\"'"

A PostgreSQL Date Format string suitable for returning dates which have been cast to UTC

Definition at line 70 of file AwlDBDialect.php.


The documentation for this class was generated from the following file: