From ab6965cda6f0458dca6055b75e9650da9af0efc7 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 29 Feb 2012 21:06:07 -0500 Subject: [PATCH] Started "get" method of query builder , added "quote_ident" method to db classes --- sys/common/db_pdo.php | 20 +++++++++++++++++--- sys/common/query_builder.php | 20 ++++++++++++++++++++ sys/databases/mysql.php | 16 ++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/sys/common/db_pdo.php b/sys/common/db_pdo.php index 72d940c..d2cfccf 100644 --- a/sys/common/db_pdo.php +++ b/sys/common/db_pdo.php @@ -147,6 +147,22 @@ abstract class DB_PDO extends PDO { echo "Error:
{$info[0]}:{$info[1]}\n{$info[2]}
"; } + // -------------------------------------------------------------------------- + + /** + * Surrounds the string with the databases identifier escape characters + * + * @param string $ident + * @return string + */ + public function quote_ident($ident) + { + // Split each identifier by the period + $hiers = explode('.', $ident); + + return '"'.implode('"."', $hiers).'"'; + } + // ------------------------------------------------------------------------- /** @@ -196,7 +212,7 @@ abstract class DB_PDO extends PDO { * * @return string */ - abstract public function backup_data(); + abstract public function backup_data(); } // ------------------------------------------------------------------------- @@ -234,7 +250,5 @@ abstract class DB_SQL { * @return string */ abstract public function limit($sql, $limit, $offset); - - } // End of db_pdo.php \ No newline at end of file diff --git a/sys/common/query_builder.php b/sys/common/query_builder.php index 9fa642f..964079b 100644 --- a/sys/common/query_builder.php +++ b/sys/common/query_builder.php @@ -18,6 +18,8 @@ */ class Query_Builder { + private $table, + /** * Constructor * @@ -70,4 +72,22 @@ class Query_Builder { } } + // -------------------------------------------------------------------------- + + /** + * Select and retrieve all records from the current table, and/or + * execute current compiled query + * + * @param $table + * @param int $limit + * @param int $offset + * @return object + */ + public function get($table='', $limit=FALSE, $offset=FALSE) + { + if ( ! empty($table) && $limit === FALSE && $offset === FALSE) + { + return $this->query('SELECT * FROM ' . $this->quote_ident($table)); + } + } } \ No newline at end of file diff --git a/sys/databases/mysql.php b/sys/databases/mysql.php index 30c409b..099314f 100644 --- a/sys/databases/mysql.php +++ b/sys/databases/mysql.php @@ -128,5 +128,21 @@ class MySQL extends DB_PDO { // @todo Implement Backup function return ''; } + + // -------------------------------------------------------------------------- + + /** + * Surrounds the string with the databases identifier escape characters + * + * @param string $ident + * @return string + */ + public function quote_ident($ident) + { + // Split each identifier by the period + $hiers = explode('.', $ident); + + return '`'.implode('`.`', $hiers).'`'; + } } //End of mysql.php \ No newline at end of file