25 if($type ==
'varchar')
26 return 'varchar('.(intval($len) ? intval($len) :
'1').
')';
29 return 'char('.(intval($len) ? intval($len) :
'1').
')';
38 $dbHelper = Main\HttpApplication::getConnection()->getSqlHelper();
42 foreach($fields as $fld)
43 $map[] = $dbHelper->forSql($fld);
46 return 'INSERT IGNORE INTO '.$dbHelper->forSql($tableName).
' ('.implode(
',', $map).
') values ';
61 return static::prepareSql($row, $fields, $map);
69 protected static function prepareSql($row, $fields, $map)
71 if (!is_array($row) || empty($row) || !is_array($fields) || empty($fields) || !is_array($map) || empty($map))
76 $connection = Main\HttpApplication::getConnection();
77 $sqlHelper = $connection->getSqlHelper();
81 foreach ($fields as $fld => $none)
87 isset($map[$fld][
'data_type'])
88 && $map[$fld][
'data_type'] ==
'integer'
95 $sql[] =
"'" . $sqlHelper->forSql($val) .
"'";
99 return '(' . implode(
',', $sql) .
')';
150 public static function createIndex($tableName, $ixNamePostfix, $columns = array(), $unique =
false)
152 if(!mb_strlen($tableName) || !mb_strlen($ixNamePostfix) || !is_array($columns) || empty($columns))
155 $dbConnection = Main\HttpApplication::getConnection();
156 $dbHelper = $dbConnection->getSqlHelper();
158 $tableName = $dbHelper->forSql($tableName);
159 $ixNamePostfix = $dbHelper->forSql($ixNamePostfix);
160 $columns = static::escapeArray($columns);
162 $ixName = static::getIndexName($tableName, $ixNamePostfix, $columns);
164 if(mb_strlen($ixName) > 30)
167 if(!static::checkIndexNameExists($ixName, $tableName))
169 $dbConnection->query(
"CREATE ".($unique ?
"UNIQUE" :
"").
" INDEX ".$ixName.
" ON ".$tableName.
" (".implode(
', ', $columns).
")");
176 protected static function getIndexName($tableName, $ixNamePostfix, $columns = array())
178 return 'IX_'.preg_replace(
'#^B_#',
'', ToUpper($tableName)).
"_".ToUpper($ixNamePostfix);
183 foreach($columns as &$col)
184 $col = Main\HttpApplication::getConnection()->getSqlHelper()->forSql($col);
191 $dbConnection = Main\HttpApplication::getConnection();
193 $tableName = $dbConnection->getSqlHelper()->forSql($tableName);
195 if($dbConnection->isTableExists($tableName))
196 Main\HttpApplication::getConnection()->query(
'drop table '.$tableName);
201 return Main\HttpApplication::getConnection()->isTableExists($tableName);
206 $dbConnection = Main\HttpApplication::getConnection();
208 $tableName = $dbConnection->getSqlHelper()->forSql($tableName);
210 if($dbConnection->isTableExists($tableName))
211 Main\HttpApplication::getConnection()->query(
'truncate table '.$tableName);
static prepareSql($row, $fields, $map)
static getSqlForDataType($type, $len=0)
static addAutoIncrement()
static escapeArray($columns)
static getBatchInsertHead($tableName, $fields=array())
static needSelectFieldsInOrderByWhenDistinct()
static incrementSequenceForTable($tableName)
static checkSequenceExistsForTable($tableName)
static getBatchInsertValues($row, $tableName, $fields, $map)
static restoreAutoIncrementRestrictions($tableName)
static createIndex($tableName, $ixNamePostfix, $columns=array(), $unique=false)
static getMaxTransferUnit()
static dropTable($tableName)
static truncateTable($tableName)
static getBatchInsertTail()
static getQuerySeparatorSql()
static dropAutoIncrementRestrictions($tableName)
static getBatchInsertSeparator()
static checkTableExists($tableName)
static getIndexName($tableName, $ixNamePostfix, $columns=array())