示例#1
0
 function __destruct()
 {
     if (isset($this->profile['single_transaction']) && $this->profile['single_transaction']) {
         $this->commit();
     }
     parent::__destruct();
 }
 function __construct($profile)
 {
     if (!function_exists('sqlite_open')) {
         throw new jException('jelix~db.error.nofunction', 'sqlite');
     }
     parent::__construct($profile);
 }
 function __construct($profile)
 {
     if (!function_exists('mysql_connect')) {
         throw new jException('jelix~db.error.nofunction', 'mysql');
     }
     parent::__construct($profile);
 }
 function __construct($profile)
 {
     if (!class_exists('SQLite3')) {
         throw new jException('jelix~db.error.nofunction', 'sqlite3');
     }
     parent::__construct($profile);
 }
 function __construct($profile)
 {
     if (!function_exists('oci_connect')) {
         throw new jException('jelix~db.error.nofunction', 'oci');
     }
     parent::__construct($profile);
     $this->dbms = 'oci';
 }
 function __construct($profile)
 {
     // à cause du @, on est obligé de tester l'existence de mysql, sinon en cas d'absence
     // on a droit à un arret sans erreur
     if (!function_exists('mysql_connect')) {
         throw new jException('jelix~db.error.nofunction', 'mysql');
     }
     parent::__construct($profile);
 }
 function __construct($profile)
 {
     // because of the @, we need to test mysl existance, else there would be
     // a stop without error
     if (!function_exists('mysql_connect')) {
         throw new jException('jelix~db.error.nofunction', 'mysql');
     }
     parent::__construct($profile);
 }
示例#8
0
 /**
  * fill correctly some properties of the column, depending of its type
  * and other properties
  * @param jDbColumn $col
  */
 function normalizeColumn($col)
 {
     $type = $this->conn->tools()->getTypeInfo($col->type);
     $col->nativeType = $type[0];
     if (!$col->length && $type[5]) {
         $col->length = $type[5];
     }
     if ($type[6]) {
         $col->autoIncrement = true;
         $col->notNull = true;
     }
 }
示例#9
0
 /**
  * prepare the value ready to be used in a dynamic evaluation
  */
 protected final function _prepareValue($value, $fieldType, $notNull = false)
 {
     if (!$notNull && $value === null) {
         return 'NULL';
     }
     switch (strtolower($fieldType)) {
         case 'int':
         case 'integer':
         case 'autoincrement':
             $value = intval($value);
             break;
         case 'double':
         case 'float':
             $value = doubleval($value);
             break;
         case 'numeric':
             //usefull for bigint and stuff
         //usefull for bigint and stuff
         case 'bigautoincrement':
             if (is_numeric($value)) {
                 //was numeric, we can sends it as is
                 // no cast with intval else overflow
                 return $value;
             } else {
                 //not a numeric, nevermind, casting it
                 return intval($value);
             }
             break;
         case 'boolean':
             if ($value === true || strtolower($value) == 'true' || $value == '1' || $value === 't') {
                 $value = $this->trueValue;
             } else {
                 $value = $this->falseValue;
             }
             break;
         default:
             $value = $this->_conn->quote($value, true, $fieldType == 'varbinary');
     }
     return $value;
 }
示例#10
0
 public function execSQLScript($file)
 {
     $lines = file($file);
     $cmdSQL = '';
     $nbCmd = 0;
     $style = $this->dbmsStyle;
     foreach ((array) $lines as $key => $line) {
         if (!preg_match($style[0], $line) && strlen(trim($line)) > 0) {
             // la ligne n'est ni vide ni commentaire
             //$line = str_replace("\\'","''",$line);
             //$line = str_replace($this->scriptReplaceFrom, $this->scriptReplaceBy,$line);
             $cmdSQL .= $line;
             if (preg_match($style[1], $line)) {
                 //Si on est à la ligne de fin de la commande on l'execute
                 // On nettoie la commande du ";" de fin et on l'execute
                 $cmdSQL = preg_replace($style[1], '', $cmdSQL);
                 $this->_connector->query($cmdSQL);
                 $nbCmd++;
                 $cmdSQL = '';
             }
         }
     }
     return $nbCmd;
 }
 /**
  * a callback function for some array_map call in generated methods
  * @since 1.2
  */
 protected function _callbackQuoteBin($value)
 {
     return $this->_conn->quote2($value, true, true);
 }
示例#12
0
 /**
  * execute a list of queries stored in a file
  * @param string $file path of the sql file
  */
 public function execSQLScript($file)
 {
     if (!isset($this->_conn->profile['table_prefix'])) {
         $prefix = '';
     } else {
         $prefix = $this->_conn->profile['table_prefix'];
     }
     $lines = file($file);
     $cmdSQL = '';
     $nbCmd = 0;
     $style = $this->dbmsStyle;
     foreach ((array) $lines as $key => $line) {
         if (!preg_match($style[0], $line) && strlen(trim($line)) > 0) {
             // The line isn't empty and isn't a comment
             //$line = str_replace("\\'","''",$line);
             //$line = str_replace($this->scriptReplaceFrom, $this->scriptReplaceBy,$line);
             $cmdSQL .= $line;
             if (preg_match($style[1], $line)) {
                 // If at the last line of the command, execute it
                 // Cleanup the command from the ending ";" and execute it
                 $cmdSQL = preg_replace($style[1], '', $cmdSQL);
                 $cmdSQL = str_replace('%%PREFIX%%', $prefix, $cmdSQL);
                 $this->_conn->exec($cmdSQL);
                 $nbCmd++;
                 $cmdSQL = '';
             }
         }
     }
     return $nbCmd;
 }