summaryrefslogtreecommitdiff
path: root/framework/Db/schema/sqlite
diff options
context:
space:
mode:
authorrojaro <>2009-07-13 13:56:07 +0000
committerrojaro <>2009-07-13 13:56:07 +0000
commitb4b2c7e5e2eadd48b344538823dcf5645939ba44 (patch)
tree7e10a68d038fe37d71f7f7a8552136cecfb38183 /framework/Db/schema/sqlite
parentd6ef8e39d858de50107950180ea111349e4b0d6f (diff)
- removed old schema directory
- some cleanups
Diffstat (limited to 'framework/Db/schema/sqlite')
-rwxr-xr-xframework/Db/schema/sqlite/TSqliteColumnSchema.php35
-rwxr-xr-xframework/Db/schema/sqlite/TSqliteCommandBuilder.php43
-rwxr-xr-xframework/Db/schema/sqlite/TSqliteSchema.php134
3 files changed, 0 insertions, 212 deletions
diff --git a/framework/Db/schema/sqlite/TSqliteColumnSchema.php b/framework/Db/schema/sqlite/TSqliteColumnSchema.php
deleted file mode 100755
index a6194fcd..00000000
--- a/framework/Db/schema/sqlite/TSqliteColumnSchema.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * TSqliteColumnSchema class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008-2009 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
-
-prado::using('System.db.schema.TDbColumnSchema');
-
-/**
- * TSqliteColumnSchema class describes the column meta data of a SQLite table.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.db.schema.sqlite
- * @since 1.0
- */
-class TSqliteColumnSchema extends TDbColumnSchema
-{
- /**
- * Extracts the default value for the column.
- * The value is typecasted to correct PHP type.
- * @param mixed the default value obtained from metadata
- */
- protected function extractDefault($defaultValue)
- {
- if($this->type==='string') // PHP 5.2.6 adds single quotes while 5.2.0 doesn't
- $this->defaultValue=trim($defaultValue,"'\"");
- else
- $this->defaultValue=$this->typecast($defaultValue);
- }
-}
diff --git a/framework/Db/schema/sqlite/TSqliteCommandBuilder.php b/framework/Db/schema/sqlite/TSqliteCommandBuilder.php
deleted file mode 100755
index ed73160a..00000000
--- a/framework/Db/schema/sqlite/TSqliteCommandBuilder.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * TSqliteCommandBuilder class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008-2009 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
-
-prado::using('System.db.schema.TDbCommandBuilder');
-
-/**
- * TSqliteCommandBuilder provides basic methods to create query commands for SQLite tables.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.db.schema.sqlite
- * @since 1.0
- */
-class TSqliteCommandBuilder extends TDbCommandBuilder
-{
- /**
- * Generates the expression for selecting rows with specified composite key values.
- * This method is overridden because SQLite does not support the default
- * IN expression with composite columns.
- * @param TDbTableSchema the table schema
- * @param array list of primary key values to be selected within
- * @param string column prefix (ended with dot)
- * @return string the expression for selection
- * @since 1.0.4
- */
- protected function createCompositeInCondition($table,$values,$prefix)
- {
- $keyNames=array();
- foreach(array_keys($values[0]) as $name)
- $keyNames[]=$prefix.$table->columns[$name]->rawName;
- $vs=array();
- foreach($values as $value)
- $vs[]=implode("||','||",$value);
- return implode("||','||",$keyNames).' IN ('.implode(', ',$vs).')';
- }
-}
diff --git a/framework/Db/schema/sqlite/TSqliteSchema.php b/framework/Db/schema/sqlite/TSqliteSchema.php
deleted file mode 100755
index 1c6ba78f..00000000
--- a/framework/Db/schema/sqlite/TSqliteSchema.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-/**
- * TSqliteSchema class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008-2009 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
-
-prado::using('System.db.schema.TDbSchema');
-prado::using('System.db.schema.TDbTableSchema');
-prado::using('System.db.schema.sqlite.TSqliteColumnSchema');
-prado::using('System.db.schema.sqlite.TSqliteCommandBuilder');
-
-/**
- * TSqliteSchema is the class for retrieving metadata information from a SQLite (2/3) database.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.db.schema.sqlite
- * @since 1.0
- */
-class TSqliteSchema extends TDbSchema
-{
- /**
- * Returns all table names in the database.
- * @param string the schema of the tables. This is not used for sqlite database.
- * @return array all table names in the database.
- * @since 1.0.2
- */
- protected function findTableNames($schema='')
- {
- $sql="SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'";
- return $this->getDbConnection()->createCommand($sql)->queryColumn();
- }
-
- /**
- * Creates a command builder for the database.
- * @return TSqliteCommandBuilder command builder instance
- */
- protected function createCommandBuilder()
- {
- return new TSqliteCommandBuilder($this);
- }
-
- /**
- * Creates a table instance representing the metadata for the named table.
- * @return TDbTableSchema driver dependent table metadata. Null if the table does not exist.
- */
- protected function createTable($name)
- {
- $db=$this->getDbConnection();
-
- $table=new TDbTableSchema;
- $table->name=$name;
- $table->rawName=$this->quoteTableName($name);
-
- if($this->findColumns($table))
- {
- $this->findConstraints($table);
- return $table;
- }
- else
- return null;
- }
-
- /**
- * Collects the table column metadata.
- * @param TDbTableSchema the table metadata
- * @return boolean whether the table exists in the database
- */
- protected function findColumns($table)
- {
- $sql="PRAGMA table_info({$table->rawName})";
- $columns=$this->getDbConnection()->createCommand($sql)->queryAll();
- if(empty($columns))
- return false;
-
- foreach($columns as $column)
- {
- $c=$this->createColumn($column);
- $table->columns[$c->name]=$c;
- if($c->isPrimaryKey)
- {
- if($table->primaryKey===null)
- $table->primaryKey=$c->name;
- else if(is_string($table->primaryKey))
- $table->primaryKey=array($table->primaryKey,$c->name);
- else
- $table->primaryKey[]=$c->name;
- }
- }
- if(is_string($table->primaryKey) && !strncasecmp($table->columns[$table->primaryKey]->dbType,'int',3))
- $table->sequenceName='';
-
- return true;
- }
-
- /**
- * Collects the foreign key column details for the given table.
- * @param TDbTableSchema the table metadata
- */
- protected function findConstraints($table)
- {
- $foreignKeys=array();
- $sql="PRAGMA foreign_key_list({$table->rawName})";
- $keys=$this->getDbConnection()->createCommand($sql)->queryAll();
- foreach($keys as $key)
- {
- $column=$table->columns[$key['from']];
- $column->isForeignKey=true;
- $foreignKeys[$key['from']]=array($key['table'],$key['to']);
- }
- $table->foreignKeys=$foreignKeys;
- }
-
- /**
- * Creates a table column.
- * @param array column metadata
- * @return TDbColumnSchema normalized column metadata
- */
- protected function createColumn($column)
- {
- $c=new TSqliteColumnSchema;
- $c->name=$column['name'];
- $c->rawName=$this->quoteColumnName($c->name);
- $c->allowNull=!$column['notnull'];
- $c->isPrimaryKey=$column['pk']!=0;
- $c->isForeignKey=false;
- $c->init(strtolower($column['type']),$column['dflt_value']);
- return $c;
- }
-}