Esempio n. 1
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);
     }
 }
Esempio n. 2
0
 /**
  * Override for the default SQL generation functions, MySQL-specific field generation function
  * 
  * @param string $name
  * @param array $def
  * @return string
  */
 protected function _generateFieldSchema($name, $def)
 {
     switch ($def[0]) {
         case QUICKBOOKS_DRIVER_SQL_SERIAL:
             $sql = $name . ' int(10) unsigned NOT NULL ';
             // AUTO_INCREMENT
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP:
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP_ON_INSERT_OR_UPDATE:
             $sql = $name . ' TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ';
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP_ON_UPDATE:
             $sql = $name . ' TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP ';
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_TIMESTAMP_ON_INSERT:
             $sql = $name . ' TIMESTAMP DEFAULT CURRENT_TIMESTAMP ';
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_BOOLEAN:
             $sql = $name . ' tinyint(1) ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' DEFAULT 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;
         default:
             return parent::_generateFieldSchema($name, $def);
     }
 }
Esempio n. 3
0
 /**
  * Override for the default SQL generation functions, PostgreSQL-specific field generation function
  * 
  * @param string $name
  * @param array $def
  * @return string
  */
 protected function _generateFieldSchema($name, $def)
 {
     switch ($def[0]) {
         case QUICKBOOKS_DRIVER_SQL_SERIAL:
             $sql = $name . ' SERIAL NOT NULL ';
             // AUTO_INCREMENT
             return $sql;
         case QUICKBOOKS_DRIVER_SQL_DATETIME:
             $sql = $name . ' timestamp without time zone ';
             if (isset($def[2])) {
                 if (strtolower($def[2]) == 'null') {
                     $sql .= ' DEFAULT NULL ';
                 } else {
                     $sql .= ' DEFAULT ' . $def[2] . ' NOT NULL ';
                 }
             } else {
                 $sql .= ' NOT NULL ';
             }
             return $sql;
         default:
             return parent::_generateFieldSchema($name, $def);
     }
 }