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
@ -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

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,29 +18,7 @@
* @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

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