コード例 #1
0
 protected function _generateCreateTable($name, $arr, $primary = array(), $keys = array())
 {
     $arr_sql = parent::_generateCreateTable($name, $arr, $primary, $keys);
     if (is_array($primary) and count($primary) == 1) {
         $primary = current($primary);
     }
     if (is_array($primary)) {
         //ALTER TABLE  `quickbooks_ident` ADD PRIMARY KEY (  `qb_action` ,  `unique_id` )
         $arr_sql[] = 'ALTER TABLE ' . $name . ' ADD PRIMARY KEY ( ' . implode(', ', $primary) . ' ) ';
     } else {
         if ($primary) {
             $arr_sql[] = 'ALTER TABLE ' . $name . ' ADD PRIMARY KEY(' . $primary . '); ';
             if ($arr[$primary][0] == QUICKBOOKS_DRIVER_SQL_SERIAL) {
                 // add the auto-increment
                 $arr_sql[] = 'ALTER TABLE ' . $name . ' CHANGE ' . $primary . ' ' . $primary . ' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;';
             }
         }
     }
     foreach ($keys as $key) {
         if (is_array($key)) {
             $arr_sql[] = 'ALTER TABLE ' . $name . ' ADD INDEX(' . implode(', ', $key) . ');';
         } else {
             $arr_sql[] = 'ALTER TABLE ' . $name . ' ADD INDEX(' . $key . ');';
         }
     }
     return $arr_sql;
 }
コード例 #2
0
 /**
  * Override for the default SQL generation functions, MSSQL-specific field generation function
  * 
  * The Microsoft SQL Server PHP module is retarded, and for some reason 
  * decides to cast anything as DEFAULT NULL unless you specify them just as 
  * NULL. Specifying DEFAULT NULL doesn't work. This is contrary to the 
  * actual SQL Server Studio tool, which actually works like it should. 
  * 
  * WTF? Seriously, I just wasted like 4 hours trying to figure out what I 
  * did wrong, and it turns out the stupid module is just stupid. 
  * 
  * @param string $name
  * @param array $def
  * @return string
  */
 protected function _generateFieldSchema($name, $def)
 {
     $sql = '';
     switch ($def[0]) {
         case QUICKBOOKS_DRIVER_SQL_SERIAL:
             $sql = $name . ' integer NOT NULL IDENTITY(1, 1) ';
             // AUTO_INCREMENT
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP:
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP_ON_INSERT_OR_UPDATE:
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP_ON_UPDATE:
             $sql = $name . ' TIMESTAMP ';
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_DATETIME:
         case QUICKBOOKS_DRIVER_SQL_DATE:
             $sql = $name . ' DATETIME ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 }
             } else {
                 $sql .= ' NOT NULL ';
             }
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_VARCHAR:
             $sql = $name . ' VARCHAR';
             /*if ($name == 'ListID')
             		{
             			print('LIST ID:');
             			print_r($def);
             		}*/
             if (!empty($def[1])) {
                 $sql .= '(' . (int) $def[1] . ') ';
             }
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 } else {
                     if ($def[2] === false) {
                         $sql .= ' NOT NULL ';
                     } else {
                         $sql .= " NOT NULL DEFAULT '" . $def[2] . "' ";
                     }
                 }
             } else {
                 $sql .= ' NOT NULL ';
             }
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_CHAR:
             $sql = $name . ' CHAR';
             if (!empty($def[1])) {
                 $sql .= '(' . (int) $def[1] . ') ';
             }
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 } else {
                     $sql .= " NOT NULL DEFAULT '" . $def[2] . "' ";
                 }
             } else {
                 $sql .= ' NOT NULL ';
             }
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_TEXT:
             $sql = $name . ' TEXT ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 } else {
                     $sql .= " NOT NULL DEFAULT '" . $def[2] . "' ";
                 }
             } else {
                 $sql .= ' NOT NULL ';
             }
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_INTEGER:
             $sql = $name . ' INTEGER ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 } else {
                     $sql .= ' DEFAULT ' . (int) $def[2];
                 }
             }
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_BOOLEAN:
             $sql = $name . ' tinyint ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' NULL ';
                 } else {
                     if ($def[2]) {
                         $sql .= ' DEFAULT 1 ';
                     } else {
                         $sql .= ' DEFAULT 0 ';
                     }
                 }
             }
             return $sql;
             /*case QUICKBOOKS_DRIVER_SQL_INTEGER:
             		$sql = $name . ' int(10) unsigned ';
             		
             		if (isset($def[2]))
             		{
             			if (strtolower($def[2]) == 'null')
             			{
             				$sql .= ' DEFAULT NULL ';
             			}
             			else
             			{
             				$sql .= ' DEFAULT ' . (int) $def[2];
             			}
             		}
             		else
             		{
             			$sql .= ' NOT NULL ';
             		}
             		
             		return $sql;*/
         /*case QUICKBOOKS_DRIVER_SQL_INTEGER:
         		$sql = $name . ' int(10) unsigned ';
         		
         		if (isset($def[2]))
         		{
         			if (strtolower($def[2]) == 'null')
         			{
         				$sql .= ' DEFAULT NULL ';
         			}
         			else
         			{
         				$sql .= ' DEFAULT ' . (int) $def[2];
         			}
         		}
         		else
         		{
         			$sql .= ' NOT NULL ';
         		}
         		
         		return $sql;*/
         default:
             return parent::_generateFieldSchema($name, $def);
     }
 }
コード例 #3
0
    /**
     * Override for the default SQL generation functions, PostgreSQL-specific field generation function
     * 
     * @param string $name
     * @param array $arr
     * @param array $primary
     * @param array $keys
     * @return array
     */
    protected function _generateCreateTable($name, $arr, $primary = array(), $keys = array())
    {
        $arr_sql = parent::_generateCreateTable($name, $arr, $primary, $keys);
        if (is_array($primary) and count($primary) == 1) {
            $primary = current($primary);
        }
        if (is_array($primary)) {
            //ALTER TABLE  `quickbooks_ident` ADD PRIMARY KEY (  `qb_action` ,  `unique_id` )
            //$arr_sql[] = 'ALTER TABLE ' . $name . ' ADD PRIMARY KEY ( ' . implode(', ', $primary) . ' ) ';
        } else {
            if ($primary) {
                $arr_sql[] = 'ALTER TABLE ONLY ' . $name . ' 
				ADD CONSTRAINT ' . $name . '_pkey PRIMARY KEY (' . $primary . ');';
            }
        }
        foreach ($keys as $key) {
            if (is_array($key)) {
                $arr_sql[] = 'CREATE INDEX ' . implode('_', $key) . '_' . $name . '_index ON ' . $name . ' USING btree (' . implode(', ', $key) . ')';
            } else {
                $arr_sql[] = 'CREATE INDEX ' . $key . '_' . $name . '_index ON ' . $name . ' USING btree (' . $key . ')';
            }
        }
        return $arr_sql;
    }
コード例 #4
0
ファイル: Sqlite3.php プロジェクト: djeraseit/quickbooks-php
 protected function _generateCreateTable($name, $arr, $primary = array(), $keys = array(), $uniques = array(), $if_not_exists = true)
 {
     $arr_sql = parent::_generateCreateTable($name, $arr, $primary, $keys, $uniques, $if_not_exists);
     if (is_array($primary) and count($primary) == 1) {
         $primary = current($primary);
     }
     return $arr_sql;
 }
コード例 #5
0
ファイル: Pgsql.php プロジェクト: djeraseit/quickbooks-php
 /**
  * Insert a new record into an SQL table
  * 
  * @param string $table
  * @param object $object
  * @return boolean
  */
 public function insert($table, $object, $discov_and_resync = true)
 {
     $this->last_insert_table = $table;
     return parent::insert($table, $object, $discov_and_resync);
 }