summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorwei <>2007-05-03 01:37:21 +0000
committerwei <>2007-05-03 01:37:21 +0000
commitea9e7eb535b460218b693d4e5fec80297eb3e360 (patch)
tree8dc4f4ac6d29989ba912a6013ffa6590c71e857d /framework
parent1ae09931b2572d9c3067c99f841a60cb3330b3f3 (diff)
Add northwind db demo.
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/ActiveRecord/Scaffold/InputBuilder/TMssqlScaffoldInput.php6
-rw-r--r--framework/Data/Common/Mysql/TMysqlCommandBuilder.php27
-rw-r--r--framework/Data/Common/Mysql/TMysqlTableInfo.php10
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php70
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlTableInfo.php10
5 files changed, 122 insertions, 1 deletions
diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMssqlScaffoldInput.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMssqlScaffoldInput.php
index 840e5b63..2f06368e 100644
--- a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMssqlScaffoldInput.php
+++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMssqlScaffoldInput.php
@@ -35,7 +35,11 @@ class TMssqlScaffoldInput extends TScaffoldInputCommon
case 'datetime': case 'smalldatetime':
return $this->getDateTimeValue($container,$column, $record);
default:
- return $this->getDefaultControlValue($container,$column, $record);
+ $value = $this->getDefaultControlValue($container,$column, $record);
+ if(trim($value)==='' && $column->getAllowNull())
+ return null;
+ else
+ return $value;
}
}
}
diff --git a/framework/Data/Common/Mysql/TMysqlCommandBuilder.php b/framework/Data/Common/Mysql/TMysqlCommandBuilder.php
new file mode 100644
index 00000000..9fd02d32
--- /dev/null
+++ b/framework/Data/Common/Mysql/TMysqlCommandBuilder.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * TMysqlCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TMysqlCommandBuilder implements default TDbCommandBuilder
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TMysqlCommandBuilder extends TDbCommandBuilder
+{
+}
+
+?> \ No newline at end of file
diff --git a/framework/Data/Common/Mysql/TMysqlTableInfo.php b/framework/Data/Common/Mysql/TMysqlTableInfo.php
index 9bc01717..3584bb3b 100644
--- a/framework/Data/Common/Mysql/TMysqlTableInfo.php
+++ b/framework/Data/Common/Mysql/TMysqlTableInfo.php
@@ -44,6 +44,16 @@ class TMysqlTableInfo extends TDbTableInfo
else
return '`'.$this->getTableName().'`';
}
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Mysql.TMysqlCommandBuilder');
+ return new TMysqlCommandBuilder($connection,$this);
+ }
}
?> \ No newline at end of file
diff --git a/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php b/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php
new file mode 100644
index 00000000..9a818ab9
--- /dev/null
+++ b/framework/Data/Common/Pgsql/TPgsqlCommandBuilder.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * TPgsqlCommandBuilder class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ */
+
+Prado::using('System.Data.Common.TDbCommandBuilder');
+
+/**
+ * TPgsqlCommandBuilder provides specifics methods to create limit/offset query commands
+ * for Pgsql database.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $
+ * @package System.Data.Common
+ * @since 3.1
+ */
+class TPgsqlCommandBuilder extends TDbCommandBuilder
+{
+ /**
+ * Overrides parent implementation. Only column of type text or character (and its variants)
+ * accepts the LIKE criteria.
+ * @param array list of column id for potential search condition.
+ * @param string string of keywords
+ * @return string SQL search condition matching on a set of columns.
+ */
+ public function getSearchExpression($fields, $keywords)
+ {
+ $columns = array();
+ foreach($fields as $field)
+ {
+ if($this->isSearchableColumn($this->getTableInfo()->getColumn($field)))
+ $columns[] = $field;
+ }
+ return parent::getSearchExpression($columns, $keywords);
+ }
+ /**
+ *
+ * @return boolean true if column can be used for LIKE searching.
+ */
+ protected function isSearchableColumn($column)
+ {
+ $type = strtolower($column->getDbType());
+ return $type === 'character varying' || $type === 'varchar' ||
+ $type === 'character' || $type === 'char' || $type === 'text';
+ }
+
+ /**
+ * Overrides parent implementation to use PostgreSQL's ILIKE instead of LIKE (case-sensitive).
+ * @param string column name.
+ * @param array keywords
+ * @return string search condition for all words in one column.
+ */
+ protected function getSearchCondition($column, $words)
+ {
+ $conditions=array();
+ foreach($words as $word)
+ $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
+ return '('.implode(' AND ', $conditions).')';
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
index a2670fe0..c25fbdf4 100644
--- a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
+++ b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
@@ -44,6 +44,16 @@ class TPgsqlTableInfo extends TDbTableInfo
else
$this->getTableName();
}
+
+ /**
+ * @param TDbConnection database connection.
+ * @return TDbCommandBuilder new command builder
+ */
+ public function createCommandBuilder($connection)
+ {
+ Prado::using('System.Data.Common.Pgsql.TPgsqlCommandBuilder');
+ return new TPgsqlCommandBuilder($connection,$this);
+ }
}
?> \ No newline at end of file