Add abstract class for sql classes to have base limit method
This commit is contained in:
parent
3a16f3c65b
commit
5b908f5816
45
classes/abstract_sql.php
Normal file
45
classes/abstract_sql.php
Normal 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
|
@ -19,7 +19,7 @@
|
||||
* @package Query
|
||||
* @subpackage Query
|
||||
*/
|
||||
interface iDB_SQL {
|
||||
interface iSQL {
|
||||
|
||||
/**
|
||||
* Get database specific sql for limit clause
|
||||
@ -121,4 +121,4 @@ interface iDB_SQL {
|
||||
public function column_list($table);
|
||||
|
||||
}
|
||||
// End of db_sql.php
|
||||
// End of isql.php
|
@ -19,7 +19,7 @@
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
*/
|
||||
class Firebird_SQL implements iDB_SQL {
|
||||
class Firebird_SQL extends Abstract_SQL {
|
||||
|
||||
/**
|
||||
* Limit clause
|
||||
|
@ -19,7 +19,7 @@
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
*/
|
||||
class MySQL_SQL implements iDB_SQL {
|
||||
class MySQL_SQL extends Abstract_SQL {
|
||||
|
||||
/**
|
||||
* Limit clause
|
||||
|
@ -18,29 +18,7 @@
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
*/
|
||||
class PgSQL_SQL implements iDB_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;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
class PgSQL_SQL extends Abstract_SQL {
|
||||
|
||||
/**
|
||||
* Get the query plan for the sql query
|
||||
|
@ -19,29 +19,7 @@
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
*/
|
||||
class SQLite_SQL implements iDB_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;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
class SQLite_SQL extends Abstract_SQL {
|
||||
|
||||
/**
|
||||
* Get the query plan for the sql query
|
||||
|
Loading…
Reference in New Issue
Block a user