]> git.andy128k.dev Git - ipf.git/commitdiff
ORM Expression for Mysql
authoravl <alex.litovchenko@gmail.com>
Wed, 3 Sep 2008 21:57:55 +0000 (00:57 +0300)
committeravl <alex.litovchenko@gmail.com>
Wed, 3 Sep 2008 21:57:55 +0000 (00:57 +0300)
ipf/admin/models/_generated/BaseAdminLog.php
ipf/auth/models/_generated/BasePermission.php
ipf/auth/models/_generated/BaseRole.php
ipf/auth/models/_generated/BaseRolePermission.php
ipf/auth/models/_generated/BaseUser.php
ipf/auth/models/_generated/BaseUserPermission.php
ipf/auth/models/_generated/BaseUserRole.php
ipf/orm/expression.php [new file with mode: 0644]
ipf/orm/expression/driver.php [new file with mode: 0644]
ipf/orm/expression/mysql.php [new file with mode: 0644]
ipf/session/models/_generated/BaseSession.php

index 31b037eab592de13c448670d207eb598d0bf6114..930e5eb311643c9d636a349d91fe0d37114684f0 100644 (file)
@@ -1,34 +1,34 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseAdminLog extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('admin_log');\r
-    $this->hasColumn('username', 'string', 32, array('type' => 'string', 'length' => '32'));\r
-    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer'));\r
-    $this->hasColumn('object_id', 'integer', null, array('type' => 'integer'));\r
-    $this->hasColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200'));\r
-    $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200'));\r
-    $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer'));\r
-    $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200'));\r
-\r
-\r
-    $this->index('idx_object_id', array('fields' => 'object_id'));\r
-    $this->index('idx_object_class', array('fields' => 'object_class'));\r
-    $this->index('idx_created_at', array('fields' => 'created_at'));\r
-    $this->index('idx_action_flag', array('fields' => 'action_flag'));\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $timestampable0 = new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true)));\r
-    $this->actAs($timestampable0);\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseAdminLog extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('admin_log');
+    $this->hasColumn('username', 'string', 32, array('type' => 'string', 'length' => '32'));
+    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer'));
+    $this->hasColumn('object_id', 'integer', null, array('type' => 'integer'));
+    $this->hasColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200'));
+    $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200'));
+    $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer'));
+    $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200'));
+
+
+    $this->index('idx_object_id', array('fields' => 'object_id'));
+    $this->index('idx_object_class', array('fields' => 'object_class'));
+    $this->index('idx_created_at', array('fields' => 'created_at'));
+    $this->index('idx_action_flag', array('fields' => 'action_flag'));
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $timestampable0 = new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true)));
+    $this->actAs($timestampable0);
+  }
 }
\ No newline at end of file
index 1fabde24cbc7b5f76b07e7e91bec66555452ade5..4be989166a207f7637725be1ec0f60efc7f58064 100644 (file)
@@ -1,30 +1,30 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BasePermission extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_permission');\r
-    $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255'));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasMany('User as Users', array('refClass' => 'UserPermission',\r
-                                          'local' => 'permission_id',\r
-                                          'foreign' => 'user_id'));\r
-\r
-    $this->hasMany('RolePermission', array('local' => 'id',\r
-                                           'foreign' => 'permission_id'));\r
-\r
-    $this->hasMany('UserPermission', array('local' => 'id',\r
-                                           'foreign' => 'permission_id'));\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BasePermission extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_permission');
+    $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255'));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasMany('User as Users', array('refClass' => 'UserPermission',
+                                          'local' => 'permission_id',
+                                          'foreign' => 'user_id'));
+
+    $this->hasMany('RolePermission', array('local' => 'id',
+                                           'foreign' => 'permission_id'));
+
+    $this->hasMany('UserPermission', array('local' => 'id',
+                                           'foreign' => 'permission_id'));
+  }
 }
\ No newline at end of file
index d48cde086fb6cc1cc948c4769025575d117a9137..6486330b9935c3d9eb8579106c2cb1cef952c796 100644 (file)
@@ -1,30 +1,30 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseRole extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_role');\r
-    $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255'));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasMany('User as Users', array('refClass' => 'UserRole',\r
-                                          'local' => 'role_id',\r
-                                          'foreign' => 'user_id'));\r
-\r
-    $this->hasMany('RolePermission', array('local' => 'id',\r
-                                           'foreign' => 'role_id'));\r
-\r
-    $this->hasMany('UserRole', array('local' => 'id',\r
-                                     'foreign' => 'role_id'));\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseRole extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_role');
+    $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255'));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasMany('User as Users', array('refClass' => 'UserRole',
+                                          'local' => 'role_id',
+                                          'foreign' => 'user_id'));
+
+    $this->hasMany('RolePermission', array('local' => 'id',
+                                           'foreign' => 'role_id'));
+
+    $this->hasMany('UserRole', array('local' => 'id',
+                                     'foreign' => 'role_id'));
+  }
 }
\ No newline at end of file
index 5f49ef43c90145218b5ee2160bb2e56dfce6c8df..807bb5b41758bd40dc18d6ec70baff88ae714aa1 100644 (file)
@@ -1,27 +1,27 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseRolePermission extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_role_permission');\r
-    $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-    $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasOne('Role', array('local' => 'role_id',\r
-                                'foreign' => 'id'));\r
-\r
-    $this->hasOne('Permission', array('local' => 'permission_id',\r
-                                      'foreign' => 'id'));\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseRolePermission extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_role_permission');
+    $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+    $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasOne('Role', array('local' => 'role_id',
+                                'foreign' => 'id'));
+
+    $this->hasOne('Permission', array('local' => 'permission_id',
+                                      'foreign' => 'id'));
+  }
 }
\ No newline at end of file
index 7f4f7721dc99107cffb103f60c5e4d0bb68b59a4..85e5e88255959c4b074f4c52b2da8bc9b3bc5b9a 100644 (file)
@@ -1,45 +1,45 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseUser extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_user');\r
-    $this->hasColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32'));\r
-    $this->hasColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128'));\r
-    $this->hasColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32'));\r
-    $this->hasColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32'));\r
-    $this->hasColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200'));\r
-    $this->hasColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));\r
-    $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));\r
-    $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));\r
-    $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp'));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasMany('Role as Roles', array('refClass' => 'UserRole',\r
-                                          'local' => 'user_id',\r
-                                          'foreign' => 'role_id'));\r
-\r
-    $this->hasMany('Permission as Permissions', array('refClass' => 'UserPermission',\r
-                                                      'local' => 'user_id',\r
-                                                      'foreign' => 'permission_id'));\r
-\r
-    $this->hasMany('UserRole', array('local' => 'id',\r
-                                     'foreign' => 'user_id'));\r
-\r
-    $this->hasMany('UserPermission', array('local' => 'id',\r
-                                           'foreign' => 'user_id'));\r
-\r
-    $timestampable0 = new IPF_ORM_Template_Timestampable();\r
-    $this->actAs($timestampable0);\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseUser extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_user');
+    $this->hasColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32'));
+    $this->hasColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128'));
+    $this->hasColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32'));
+    $this->hasColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32'));
+    $this->hasColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200'));
+    $this->hasColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));
+    $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));
+    $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));
+    $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp'));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasMany('Role as Roles', array('refClass' => 'UserRole',
+                                          'local' => 'user_id',
+                                          'foreign' => 'role_id'));
+
+    $this->hasMany('Permission as Permissions', array('refClass' => 'UserPermission',
+                                                      'local' => 'user_id',
+                                                      'foreign' => 'permission_id'));
+
+    $this->hasMany('UserRole', array('local' => 'id',
+                                     'foreign' => 'user_id'));
+
+    $this->hasMany('UserPermission', array('local' => 'id',
+                                           'foreign' => 'user_id'));
+
+    $timestampable0 = new IPF_ORM_Template_Timestampable();
+    $this->actAs($timestampable0);
+  }
 }
\ No newline at end of file
index f8cfbd762c87926d610ce164169c90739ee5f4e1..988247a0b3eb7c62052d52ddad4ad41a4f097ea0 100644 (file)
@@ -1,27 +1,27 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseUserPermission extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_user_permission');\r
-    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-    $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasOne('User', array('local' => 'user_id',\r
-                                'foreign' => 'id'));\r
-\r
-    $this->hasOne('Permission', array('local' => 'permission_id',\r
-                                      'foreign' => 'id'));\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseUserPermission extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_user_permission');
+    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+    $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasOne('User', array('local' => 'user_id',
+                                'foreign' => 'id'));
+
+    $this->hasOne('Permission', array('local' => 'permission_id',
+                                      'foreign' => 'id'));
+  }
 }
\ No newline at end of file
index ec5b476b8190c16ce4a45a3bb6df9deab2e5735a..363ff0113f56b57cc1cde250038fac95e7c606d2 100644 (file)
@@ -1,27 +1,27 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseUserRole extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('auth_user_role');\r
-    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-    $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));\r
-\r
-    $this->option('type', 'INNODB');\r
-    $this->option('collate', 'utf8_unicode_ci');\r
-    $this->option('charset', 'utf8');\r
-  }\r
-\r
-  public function setUp()\r
-  {\r
-    $this->hasOne('User', array('local' => 'user_id',\r
-                                'foreign' => 'id'));\r
-\r
-    $this->hasOne('Role', array('local' => 'role_id',\r
-                                'foreign' => 'id'));\r
-  }\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseUserRole extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('auth_user_role');
+    $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+    $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));
+
+    $this->option('type', 'INNODB');
+    $this->option('collate', 'utf8_unicode_ci');
+    $this->option('charset', 'utf8');
+  }
+
+  public function setUp()
+  {
+    $this->hasOne('User', array('local' => 'user_id',
+                                'foreign' => 'id'));
+
+    $this->hasOne('Role', array('local' => 'role_id',
+                                'foreign' => 'id'));
+  }
 }
\ No newline at end of file
diff --git a/ipf/orm/expression.php b/ipf/orm/expression.php
new file mode 100644 (file)
index 0000000..a866412
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+
+class IPF_ORM_Expression
+{
+    protected $_expression;
+    protected $_conn;
+    protected $_tokenizer;
+
+    public function __construct($expr, $conn = null)
+    {
+        $this->_tokenizer = new IPF_ORM_Query_Tokenizer();
+        $this->setExpression($expr);
+        if ($conn !== null) {
+            $this->_conn = $conn;
+        }
+    }
+
+    public function getConnection()
+    {
+        if ( ! isset($this->_conn)) {
+            return IPF_ORM_Manager::connection();
+        }
+
+        return $this->_conn;
+    }
+
+    public function setExpression($clause)
+    {
+        $this->_expression = $this->parseClause($clause);
+    }
+
+    public function parseExpression($expr)
+    {
+        $pos  = strpos($expr, '(');
+        $quoted = (substr($expr, 0, 1) === "'" && substr($expr, -1) === "'");
+        if ($pos === false || $quoted) {
+            return $expr;
+        }
+
+        // get the name of the function
+        $name   = substr($expr, 0, $pos);
+        $argStr = substr($expr, ($pos + 1), -1);
+
+        // parse args
+        foreach ($this->_tokenizer->bracketExplode($argStr, ',') as $arg) {
+           $args[] = $this->parseClause($arg);
+        }
+
+        return call_user_func_array(array($this->getConnection()->expression, $name), $args);
+    }
+
+    public function parseClause($clause)
+    {
+        $e = $this->_tokenizer->bracketExplode($clause, ' ');
+
+        foreach ($e as $k => $expr) {
+            $e[$k] = $this->parseExpression($expr);
+        }
+        
+        return implode(' ', $e);
+    }
+
+    public function getSql()
+    {
+        return $this->_expression;
+    }
+
+    public function __toString()
+    {
+        return $this->getSql();
+    }
+}
diff --git a/ipf/orm/expression/driver.php b/ipf/orm/expression/driver.php
new file mode 100644 (file)
index 0000000..a256d8e
--- /dev/null
@@ -0,0 +1,280 @@
+<?php
+
+class IPF_ORM_Expression_Driver extends IPF_ORM_Connection_Module
+{
+    public function getIdentifier($column)
+    {
+        return $column;
+    }
+    public function getIdentifiers($columns)
+    {
+        return $columns;
+    }
+
+    public function regexp()
+    {
+        throw new IPF_ORM_Exception('Regular expression operator is not supported by this database driver.');
+    }
+
+    public function avg($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'AVG(' .  $column . ')';
+    }
+
+    public function count($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'COUNT(' . $column . ')';
+    }
+
+    public function max($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'MAX(' . $column . ')';
+    }
+
+    public function min($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'MIN(' . $column . ')';
+    }
+
+    public function sum($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'SUM(' . $column . ')';
+    }
+
+    public function md5($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'MD5(' . $column . ')';
+    }
+
+    public function length($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'LENGTH(' . $column . ')';
+    }
+
+    public function round($column, $decimals = 0)
+    {
+        $column = $this->getIdentifier($column);
+
+        return 'ROUND(' . $column . ', ' . $decimals . ')';
+    }
+
+    public function mod($expression1, $expression2)
+    {
+        $expression1 = $this->getIdentifier($expression1);
+        $expression2 = $this->getIdentifier($expression2);
+        return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
+    }
+
+    public function trim($str)
+    {
+        return 'TRIM(' . $str . ')';
+    }
+
+    public function rtrim($str)
+    {
+        return 'RTRIM(' . $str . ')';
+    }
+
+    public function ltrim($str)
+    {
+        return 'LTRIM(' . $str . ')';
+    }
+
+    public function upper($str)
+    {
+        return 'UPPER(' . $str . ')';
+    }
+
+    public function lower($str)
+    {
+        return 'LOWER(' . $str . ')';
+    }
+
+    public function locate($str, $substr)
+    {
+        return 'LOCATE(' . $str . ', ' . $substr . ')';
+    }
+
+    public function now()
+    {
+        return 'NOW()';
+    }
+
+    public function soundex($value)
+    {
+        throw new IPF_ORM_Exception('SQL soundex function not supported by this driver.');
+    }
+
+    public function substring($value, $from, $len = null)
+    {
+        $value = $this->getIdentifier($value);
+        if ($len === null)
+            return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
+        else {
+            $len = $this->getIdentifier($len);
+            return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')';
+        }
+    }
+
+    public function concat()
+    {
+        $args = func_get_args();
+
+        return 'CONCAT(' . join(', ', (array) $args) . ')';
+    }
+
+    public function not($expression)
+    {
+        $expression = $this->getIdentifier($expression);
+        return 'NOT(' . $expression . ')';
+    }
+
+    private function basicMath($type, array $args)
+    {
+        $elements = $this->getIdentifiers($args);
+        if (count($elements) < 1) {
+            return '';
+        }
+        if (count($elements) == 1) {
+            return $elements[0];
+        } else {
+            return '(' . implode(' ' . $type . ' ', $elements) . ')';
+        }
+    }
+
+    public function add(array $args)
+    {
+        return $this->basicMath('+', $args);
+    }
+
+    public function sub(array $args)
+    {
+        return $this->basicMath('-', $args );
+    }
+
+    public function mul(array $args)
+    {
+        return $this->basicMath('*', $args);
+    }
+
+    public function div(array $args)
+    {
+        return $this->basicMath('/', $args);
+    }
+
+    public function eq($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' = ' . $value2;
+    }
+
+    public function neq($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' <> ' . $value2;
+    }
+
+    public function gt($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' > ' . $value2;
+    }
+
+    public function gte($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' >= ' . $value2;
+    }
+
+    public function lt($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' < ' . $value2;
+    }
+
+    public function lte($value1, $value2)
+    {
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $value1 . ' <= ' . $value2;
+    }
+
+    public function in($column, $values)
+    {
+        if ( ! is_array($values)) {
+            $values = array($values);
+        }
+        $values = $this->getIdentifiers($values);
+        $column = $this->getIdentifier($column);
+
+        if (count($values) == 0) {
+            throw new IPF_ORM_Exception('Values array for IN operator should not be empty.');
+        }
+        return $column . ' IN (' . implode(', ', $values) . ')';
+    }
+
+    public function isNull($expression)
+    {
+        $expression = $this->getIdentifier($expression);
+        return $expression . ' IS NULL';
+    }
+
+    public function isNotNull($expression)
+    {
+        $expression = $this->getIdentifier($expression);
+        return $expression . ' IS NOT NULL';
+    }
+
+    public function between($expression, $value1, $value2)
+    {
+        $expression = $this->getIdentifier($expression);
+        $value1 = $this->getIdentifier($value1);
+        $value2 = $this->getIdentifier($value2);
+        return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2;
+    }
+
+    public function guid()
+    {
+        throw new IPF_ORM_Exception('method not implemented');
+    }
+
+    public function acos($value)
+    {
+        return 'ACOS(' . $value . ')';
+    }
+
+    public function sin($value)
+    {
+        return 'SIN(' . $value . ')';
+    }
+
+    public function pi()
+    {
+        return 'PI()';
+    }
+
+    public function cos($value)
+    {
+        return 'COS(' . $value . ')';
+    }
+
+    public function __call($m, $a) 
+    {
+        if ($this->conn->getAttribute(IPF_ORM::ATTR_PORTABILITY) & IPF_ORM::PORTABILITY_EXPR) {
+            throw new IPF_ORM_Exception('Unknown expression ' . $m);
+        }
+        return $m . '(' . implode(', ', $a) . ')';
+    }
+}
\ No newline at end of file
diff --git a/ipf/orm/expression/mysql.php b/ipf/orm/expression/mysql.php
new file mode 100644 (file)
index 0000000..8730023
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+class IPF_ORM_Expression_Mysql extends IPF_ORM_Expression_Driver
+{
+    public function regexp()
+    {
+        return 'RLIKE';
+    }
+
+    public function random()
+    {
+        return 'RAND()';
+    }
+
+    public function matchPattern($pattern, $operator = null, $field = null)
+    {
+        $match = '';
+        if ( ! is_null($operator)) {
+            $field = is_null($field) ? '' : $field.' ';
+            $operator = strtoupper($operator);
+            switch ($operator) {
+                // case insensitive
+                case 'ILIKE':
+                    $match = $field.'LIKE ';
+                    break;
+                // case sensitive
+                case 'LIKE':
+                    $match = $field.'LIKE BINARY ';
+                    break;
+                default:
+                    throw new IPF_ORM_Exception('not a supported operator type:'. $operator);
+            }
+        }
+        $match.= "'";
+        foreach ($pattern as $key => $value) {
+            if ($key % 2) {
+                $match .= $value;
+            } else {
+                $match .= $this->conn->escapePattern($this->conn->escape($value));
+            }
+        }
+        $match.= "'";
+        $match.= $this->patternEscapeString();
+        return $match;
+    }
+
+    public function guid()
+    {
+        return 'UUID()';
+    }
+
+    public function year($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'YEAR(' .  $column . ')';
+    }
+
+    public function month($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'MONTH(' .  $column . ')';
+    }
+
+    public function day($column)
+    {
+        $column = $this->getIdentifier($column);
+        return 'DAY(' .  $column . ')';
+    }
+}
\ No newline at end of file
index 4408de9fce9b884e77de6d10139688bb2cb1a3d5..b126310ad95b67c03a8cfdd6c689a5e92b3fdb74 100644 (file)
@@ -1,16 +1,16 @@
-<?php\r
-\r
-/**\r
- * This class has been auto-generated by the IPF_ORM Framework\r
- */\r
-abstract class BaseSession extends IPF_ORM_Record\r
-{\r
-  public function setTableDefinition()\r
-  {\r
-    $this->setTableName('session');\r
-    $this->hasColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40'));\r
-    $this->hasColumn('session_data', 'string', null, array('type' => 'string'));\r
-    $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp'));\r
-  }\r
-\r
+<?php
+
+/**
+ * This class has been auto-generated by the IPF_ORM Framework
+ */
+abstract class BaseSession extends IPF_ORM_Record
+{
+  public function setTableDefinition()
+  {
+    $this->setTableName('session');
+    $this->hasColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40'));
+    $this->hasColumn('session_data', 'string', null, array('type' => 'string'));
+    $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp'));
+  }
+
 }
\ No newline at end of file