00001 <?php
00002
00003
00004
00005
00006
00007
00008 class DBSqlBuilderFactory {
00009 const SELECT = 1;
00010 const INSERT = 2;
00011 const UPDATE = 3;
00012 const DELETE = 4;
00013 const COUNT = 5;
00014 const WHERE = 6;
00015 const WHEREGROUP = 7;
00016 const REPLACE = 8;
00017
00018 private static $builders = array();
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 public static function create_builder($type, $query, $params = null) {
00029 $driver = DB::get_connection($query->get_table()->get_table_driver());
00030 $db = $driver->get_driver_name();
00031 $key = $db . '%%' . $type;
00032 if (!isset(self::$builders[$key])) {
00033 $part = false;
00034 switch ($type) {
00035 case self::SELECT:
00036 $part ='Select';
00037 break;
00038 case self::INSERT:
00039 $part = 'Insert';
00040 break;
00041 case self::UPDATE:
00042 $part = 'Update';
00043 break;
00044 case self::DELETE:
00045 $part = 'Delete';
00046 break;
00047 case self::COUNT:
00048 $part = 'Count';
00049 break;
00050 case self::WHERE:
00051 $part = 'Where';
00052 break;
00053 case self::WHEREGROUP:
00054 $part = 'WhereGroup';
00055 break;
00056 case self::REPLACE:
00057 $part = 'Replace';
00058 break;
00059 }
00060 if ($part === false) {
00061 throw new Exception(tr('Unknown SQL Builder Type: %s', 'core', array('%s' => $type)));
00062 }
00063
00064 $lower_part = strtolower($part);
00065 Load::classes_in_directory("model/base/sqlbuilder/", "dbsqlbuilder.$lower_part", 'cls');
00066 Load::classes_in_directory("model/drivers/$db/sqlbuilder/", "dbsqlbuilder.$lower_part.$db", 'cls');
00067 $cls = 'DBSqlBuilder' . $part . ucfirst($db);
00068 self::$builders[$key] = $cls;
00069 }
00070 $cls = self::$builders[$key];
00071 return new $cls($query, $params);
00072 }
00073 }