mirror of
https://github.com/xevidos/codiad.git
synced 2024-11-10 21:26:35 +01:00
Added identifier wraps and find function to sql conversions
This commit is contained in:
parent
65991d3d74
commit
cb362d58c2
@ -10,18 +10,28 @@ class sql_conversions {
|
||||
"pgsql" => "CREATE TABLE IF NOT EXISTS",
|
||||
"sqlite" => "CREATE TABLE IF NOT EXISTS",
|
||||
),
|
||||
|
||||
"delete" => array(
|
||||
|
||||
"mysql" => "DELETE",
|
||||
"pgsql" => "DELETE",
|
||||
"sqlite" => "DELETE",
|
||||
),
|
||||
|
||||
"find" => array(
|
||||
|
||||
"mysql" => "LOCATE( %string%, %substring% )",
|
||||
"pgsql" => "POSITION( %substring% in %string% )",
|
||||
"sqlite" => "INSTR( %string%, %substring% )",
|
||||
),
|
||||
|
||||
"select" => array(
|
||||
|
||||
"mysql" => "SELECT",
|
||||
"pgsql" => "SELECT",
|
||||
"sqlite" => "SELECT",
|
||||
),
|
||||
|
||||
"update" => array(
|
||||
|
||||
"mysql" => "UPDATE",
|
||||
@ -38,24 +48,28 @@ class sql_conversions {
|
||||
"pgsql" => "=",
|
||||
"sqlite" => "=",
|
||||
),
|
||||
|
||||
"less than" => array(
|
||||
|
||||
"mysql" => "<",
|
||||
"pgsql" => "<",
|
||||
"sqlite" => "<",
|
||||
),
|
||||
|
||||
"more than" => array(
|
||||
|
||||
"mysql" => ">",
|
||||
"pgsql" => ">",
|
||||
"sqlite" => ">",
|
||||
),
|
||||
|
||||
"not" => array(
|
||||
|
||||
"mysql" => "!",
|
||||
"pgsql" => "!",
|
||||
"sqlite" => "!",
|
||||
),
|
||||
|
||||
"not equal" => array(
|
||||
|
||||
"mysql" => "!=",
|
||||
@ -72,18 +86,21 @@ class sql_conversions {
|
||||
"pgsql" => "BOOL",
|
||||
"sqlite" => "BOOL",
|
||||
),
|
||||
|
||||
"int" => array(
|
||||
|
||||
"mysql" => "INT",
|
||||
"pgsql" => "INT",
|
||||
"sqlite" => "INT",
|
||||
),
|
||||
|
||||
"string" => array(
|
||||
|
||||
"mysql" => "VARCHAR",
|
||||
"pgsql" => "VARCHAR",
|
||||
"sqlite" => "VARCHAR",
|
||||
),
|
||||
|
||||
"text" => array(
|
||||
|
||||
"mysql" => "TEXT",
|
||||
@ -100,24 +117,28 @@ class sql_conversions {
|
||||
"pgsql" => "PRIMARY KEY",
|
||||
"sqlite" => "PRIMARY KEY",
|
||||
),
|
||||
|
||||
"key" => array(
|
||||
|
||||
"mysql" => "CONSTRAINT %table_name% UNIQUE(%fields%)",
|
||||
"pgsql" => "CONSTRAINT %table_name% UNIQUE(%fields%)",
|
||||
"sqlite" => "CONSTRAINT %table_name% UNIQUE(%fields%)",
|
||||
),
|
||||
|
||||
"auto increment" => array(
|
||||
|
||||
"mysql" => "AUTO_INCREMENT",
|
||||
"pgsql" => "AUTO_INCREMENT",
|
||||
"sqlite" => "AUTO_INCREMENT",
|
||||
),
|
||||
|
||||
"not null" => array(
|
||||
|
||||
"mysql" => "NOT NULL",
|
||||
"pgsql" => "NOT NULL",
|
||||
"sqlite" => "NOT NULL",
|
||||
),
|
||||
|
||||
"null" => array(
|
||||
|
||||
"mysql" => "NULL",
|
||||
@ -125,6 +146,25 @@ class sql_conversions {
|
||||
"sqlite" => "NULL",
|
||||
),
|
||||
);
|
||||
|
||||
public $wraps = array(
|
||||
|
||||
"close" => array(
|
||||
|
||||
"mysql" => "`",
|
||||
"mssql" => "]",
|
||||
"pgsql" => "\"",
|
||||
"sqlite" => "\"",
|
||||
),
|
||||
|
||||
"open" => array(
|
||||
|
||||
"mysql" => "`",
|
||||
"mssql" => "[",
|
||||
"pgsql" => "\"",
|
||||
"sqlite" => "\"",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -38,6 +38,9 @@ class sql {
|
||||
public static function create_table( $table_name, $fields=array(), $attributes=array() ) {
|
||||
|
||||
$dbtype = DBTYPE;
|
||||
$identifier_close = $this->conversions->wraps["close"][$dbtype];
|
||||
$identifier_open = $this->conversions->wraps["open"][$dbtype];
|
||||
|
||||
$query = "{$this->conversions->actions["create"][$dbtype]} {$table_name} (";
|
||||
|
||||
foreach( $fields as $id => $type ) {
|
||||
@ -59,7 +62,7 @@ class sql {
|
||||
|
||||
foreach( $fields as $field ) {
|
||||
|
||||
$fields_string .= "field,";
|
||||
$fields_string .= "{$identifier_open}field{$identifier_close},";
|
||||
}
|
||||
|
||||
$fields_string = substr( $fields_string, 0, -1 );
|
||||
|
Loading…
Reference in New Issue
Block a user