Add abstract class for sql classes to have base limit method

This commit is contained in:
Timothy Warren 2014-03-26 21:33:58 -04:00
parent 3a16f3c65b
commit 5b908f5816
6 changed files with 82 additions and 81 deletions

45
classes/abstract_sql.php Normal file
View File

@ -0,0 +1,45 @@
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012 - 2014
* @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license
* @package Query
*/
// --------------------------------------------------------------------------
/**
* parent for database manipulation subclasses
*
* @package Query
* @subpackage Query
*/
abstract class Abstract_SQL implements iSQL {
/**
* Limit clause
*
* @param string $sql
* @param int $limit
* @param int $offset
* @return string
*/
public function limit($sql, $limit, $offset=FALSE)
{
$sql .= "\nLIMIT {$limit}";
if (is_numeric($offset))
{
$sql .= " OFFSET {$offset}";
}
return $sql;
}
}
// End of abstract_sql.php

View File

@ -19,7 +19,7 @@
* @package Query * @package Query
* @subpackage Query * @subpackage Query
*/ */
interface iDB_SQL { interface iSQL {
/** /**
* Get database specific sql for limit clause * Get database specific sql for limit clause
@ -31,7 +31,7 @@ interface iDB_SQL {
* @return string * @return string
*/ */
public function limit($sql, $limit, $offset=FALSE); public function limit($sql, $limit, $offset=FALSE);
/** /**
* Modify the query to get the query plan * Modify the query to get the query plan
* *
@ -47,7 +47,7 @@ interface iDB_SQL {
* @return string * @return string
*/ */
public function random(); public function random();
/** /**
* Returns sql to list other databases * Returns sql to list other databases
* *
@ -103,16 +103,16 @@ interface iDB_SQL {
* @return string * @return string
*/ */
public function sequence_list(); public function sequence_list();
/** /**
* Return sql to list database field types * Return sql to list database field types
* *
* @return mixed * @return mixed
*/ */
public function type_list(); public function type_list();
/** /**
* Get information about the columns in the * Get information about the columns in the
* specified table * specified table
* *
* @param string $table * @param string $table
@ -121,4 +121,4 @@ interface iDB_SQL {
public function column_list($table); public function column_list($table);
} }
// End of db_sql.php // End of isql.php

View File

@ -19,7 +19,7 @@
* @package Query * @package Query
* @subpackage Drivers * @subpackage Drivers
*/ */
class Firebird_SQL implements iDB_SQL { class Firebird_SQL extends Abstract_SQL {
/** /**
* Limit clause * Limit clause
@ -45,9 +45,9 @@ class Firebird_SQL implements iDB_SQL {
return $sql; return $sql;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Get the query plan for the sql query * Get the query plan for the sql query
* *
@ -71,9 +71,9 @@ class Firebird_SQL implements iDB_SQL {
return NULL; return NULL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Returns sql to list other databases * Returns sql to list other databases
* *
@ -83,9 +83,9 @@ class Firebird_SQL implements iDB_SQL {
{ {
return NULL; return NULL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Returns sql to list tables * Returns sql to list tables
* *
@ -100,9 +100,9 @@ class Firebird_SQL implements iDB_SQL {
ORDER BY "RDB\$RELATION_NAME" ASC ORDER BY "RDB\$RELATION_NAME" ASC
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Returns sql to list system tables * Returns sql to list system tables
* *
@ -117,9 +117,9 @@ SQL;
ORDER BY "RDB\$RELATION_NAME" ASC ORDER BY "RDB\$RELATION_NAME" ASC
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Returns sql to list views * Returns sql to list views
* *
@ -132,9 +132,9 @@ SQL;
FROM "RDB\$VIEW_RELATIONS" FROM "RDB\$VIEW_RELATIONS"
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Returns sql to list triggers * Returns sql to list triggers
* *
@ -147,9 +147,9 @@ SQL;
WHERE "RDB\$SYSTEM_FLAG" = 0 WHERE "RDB\$SYSTEM_FLAG" = 0
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Return sql to list functions * Return sql to list functions
* *
@ -159,9 +159,9 @@ SQL;
{ {
return 'SELECT * FROM "RDB$FUNCTIONS"'; return 'SELECT * FROM "RDB$FUNCTIONS"';
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Return sql to list stored procedures * Return sql to list stored procedures
* *
@ -187,9 +187,9 @@ SQL;
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Return sql to list sequences * Return sql to list sequences
* *
@ -203,14 +203,14 @@ SQL;
WHERE "RDB\$SYSTEM_FLAG" = 0 WHERE "RDB\$SYSTEM_FLAG" = 0
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Return sql to list columns of the specified table * Return sql to list columns of the specified table
* *
* @param string $table * @param string $table
* @return string * @return string
*/ */
public function column_list($table) public function column_list($table)
{ {
@ -250,9 +250,9 @@ SQL;
ORDER BY r.RDB\$FIELD_POSITION ORDER BY r.RDB\$FIELD_POSITION
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* SQL to show list of field types * SQL to show list of field types
* *

View File

@ -19,7 +19,7 @@
* @package Query * @package Query
* @subpackage Drivers * @subpackage Drivers
*/ */
class MySQL_SQL implements iDB_SQL { class MySQL_SQL extends Abstract_SQL {
/** /**
* Limit clause * Limit clause

View File

@ -18,30 +18,8 @@
* @package Query * @package Query
* @subpackage Drivers * @subpackage Drivers
*/ */
class PgSQL_SQL implements iDB_SQL { class PgSQL_SQL extends Abstract_SQL {
/**
* Limit clause
*
* @param string $sql
* @param int $limit
* @param int $offset
* @return string
*/
public function limit($sql, $limit, $offset=FALSE)
{
$sql .= " LIMIT {$limit}";
if(is_numeric($offset))
{
$sql .= " OFFSET {$offset}";
}
return $sql;
}
// --------------------------------------------------------------------------
/** /**
* Get the query plan for the sql query * Get the query plan for the sql query
* *
@ -222,9 +200,9 @@ SQL;
ORDER BY ordinal_position; ORDER BY ordinal_position;
SQL; SQL;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* SQL to show list of field types * SQL to show list of field types
* *

View File

@ -19,29 +19,7 @@
* @package Query * @package Query
* @subpackage Drivers * @subpackage Drivers
*/ */
class SQLite_SQL implements iDB_SQL { class SQLite_SQL extends Abstract_SQL {
/**
* Limit clause
*
* @param string $sql
* @param int $limit
* @param int $offset
* @return string
*/
public function limit($sql, $limit, $offset=FALSE)
{
$sql .= "\nLIMIT {$limit}";
if (is_numeric($offset))
{
$sql .= " OFFSET {$offset}";
}
return $sql;
}
// --------------------------------------------------------------------------
/** /**
* Get the query plan for the sql query * Get the query plan for the sql query