📄 class.ux_t3lib_db.php
字号:
/** * Return MetaType for native field type (ADOdb only!) * * @param string native type as reported by admin_get_fields() * @param string Table name for which query type string. Important for detection of DBMS handler of the query! * @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) */ function MetaType($type,$table,$max_length=-1) { $this->lastHandlerKey = $this->handler_getFromTableList($table); switch((string)$this->handlerCfg[$this->lastHandlerKey]['type']) { case 'native': $str = $type; break; case 'adodb': $rs = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit('SELECT * FROM '.$this->quoteFromTables($table),1); $str = $rs->MetaType($type, $max_length); break; case 'userdefined': $str = $this->handlerInstance[$this->lastHandlerKey]->MetaType($str,$table,$max_length); break; default: die('No handler found!!!'); break; } return $str; } /** * Return MetaType for native MySQL field type * * @param string native type as reported as in mysqldump files * @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) */ function MySQLMetaType($t) { switch (strtoupper($t)) { case 'STRING': case 'CHAR': case 'VARCHAR': case 'TINYBLOB': case 'TINYTEXT': case 'ENUM': case 'SET': return 'C'; case 'TEXT': case 'LONGTEXT': case 'MEDIUMTEXT': return 'X'; case 'IMAGE': case 'LONGBLOB': case 'BLOB': case 'MEDIUMBLOB': return 'B'; case 'YEAR': case 'DATE': return 'D'; case 'TIME': case 'DATETIME': case 'TIMESTAMP': return 'T'; case 'FLOAT': case 'DOUBLE': return 'F'; case 'INT': case 'INTEGER': case 'TINYINT': case 'SMALLINT': case 'MEDIUMINT': case 'BIGINT': return 'I8'; // we always return I8 to be on the safe side. Under some circumstances the fields are to small otherwise... default: return 'N'; } } /** * Return actual MySQL type for meta field type * * @param string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) * @return string native type as reported as in mysqldump files, uppercase */ function MySQLActualType($meta) { switch(strtoupper($meta)) { case 'C': return 'VARCHAR'; case 'XL': case 'X': return 'LONGTEXT'; case 'C2': return 'VARCHAR'; case 'X2': return 'LONGTEXT'; case 'B': return 'LONGBLOB'; case 'D': return 'DATE'; case 'T': return 'DATETIME'; case 'L': return 'TINYINT'; case 'I': case 'I1': case 'I2': case 'I4': case 'I8': return 'BIGINT'; // we only have I8 in DBAL, see MySQLMetaType() case 'F': return 'DOUBLE'; case 'N': return 'NUMERIC'; default: return $meta; } } /************************************** * * SQL wrapper functions (Overriding parent methods) * (For use in your applications) * **************************************/ /** * Returns the error status on the most recent sql() execution (based on $this->lastHandlerKey) * * @return string Handler error strings */ function sql_error() { switch($this->handlerCfg[$this->lastHandlerKey]['type']) { case 'native': $output = mysql_error($this->handlerInstance[$this->lastHandlerKey]['link']); break; case 'adodb': $output = $this->handlerInstance[$this->lastHandlerKey]->ErrorMsg(); break; case 'userdefined': $output = $this->handlerInstance[$this->lastHandlerKey]->sql_error(); break; } return $output; } /** * Returns the number of selected rows. * * @param pointer Result pointer / DBAL object * @return integer Number of resulting rows. */ function sql_num_rows(&$res) { if($res === false) return 0; $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; switch($handlerType) { case 'native': $output = mysql_num_rows($res); break; case 'adodb': $output = method_exists($res, 'RecordCount') ? $res->RecordCount() : 0; break; case 'userdefined': $output = $res->sql_num_rows(); break; } return $output; } /** * Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. * * @param pointer MySQL result pointer (of SELECT query) / DBAL object * @return array Associative array of result row. */ function sql_fetch_assoc(&$res) { $output = array(); $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : (is_resource($res) ? 'native' : false); switch($handlerType) { case 'native': $output = mysql_fetch_assoc($res); $tableList = $this->resourceIdToTableNameMap[(string)$res]; // Reading list of tables from SELECT query: break; case 'adodb': // Check if method exists for the current $res object. // If a table exists in TCA but not in the db, a error // occured because $res is not a valid object. if(method_exists($res, 'FetchRow')) { $output = $res->FetchRow(); $tableList = $res->TYPO3_DBAL_tableList; // Reading list of tables from SELECT query: // Removing all numeric/integer keys. // A workaround because in ADOdb we would need to know what we want before executing the query... if (is_array($output)) { foreach($output as $key => $value) { if (is_integer($key)) unset($output[$key]); elseif($value===' ' && $this->runningADOdbDriver('mssql')) $output[$key]=''; // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix. } } } break; case 'userdefined': $output = $res->sql_fetch_assoc(); $tableList = $res->TYPO3_DBAL_tableList; // Reading list of tables from SELECT query: break; } // Table/Fieldname mapping: if (is_array($output)) { if ($tables = $this->map_needMapping($tableList,TRUE)) { $output = $this->map_assocArray($output,$tables,1); } } // Return result: return $output; } /** * Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. * The array contains the values in numerical indices. * * @param pointer MySQL result pointer (of SELECT query) / DBAL object * @return array Array with result rows. */ function sql_fetch_row(&$res) { $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; switch($handlerType) { case 'native': $output = mysql_fetch_row($res); break; case 'adodb': // Check if method exists for the current $res object. // If a table exists in TCA but not in the db, a error // occured because $res is not a valid object. if(method_exists($res, 'FetchRow')) { $output = $res->FetchRow(); // Removing all assoc. keys. // A workaround because in ADOdb we would need to know what we want before executing the query... if (is_array($output)) { foreach($output as $key => $value) { if (!is_integer($key)) unset($output[$key]); elseif($value===' ' && $this->runningADOdbDriver('mssql')) $output[$key]=''; // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix. } } } break; case 'userdefined': $output = $res->sql_fetch_row(); break; } return $output; } /** * Free result memory / unset result object * * @param pointer MySQL result pointer to free / DBAL object * @return boolean Returns TRUE on success or FALSE on failure. */ function sql_free_result(&$res) { if($res===false) return false; $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; switch($handlerType) { case 'native': $output = mysql_free_result($res); break; case 'adodb': if(method_exists($res, 'Close')) { $res->Close(); unset($res); $output = true; } else { $output = false; } break; case 'userdefined': unset($res); break; } return $output; } /** * Get the ID generated from the previous INSERT operation * * @return integer The uid of the last inserted record. */ function sql_insert_id() { switch($this->handlerCfg[$this->lastHandlerKey]['type']) { case 'native': $output = mysql_insert_id($this->handlerInstance[$this->lastHandlerKey]['link']); break; case 'adodb': $output = $this->handlerInstance[$this->lastHandlerKey]->last_insert_id; break; case 'userdefined': $output = $this->handlerInstance[$this->lastHandlerKey]->sql_insert_id(); break; } return $output; } /** * Returns the number of rows affected by the last INSERT, UPDATE or DELETE query * * @return integer Number of rows affected by last query */ function sql_affected_rows() { switch($this->handlerCfg[$this->lastHandlerKey]['type']) { case 'native': $output = mysql_affected_rows(); break; case 'adodb': $output = $this->handlerInstance[$this->lastHandlerKey]->Affected_Rows(); break; case 'userdefined': $output = $this->handlerInstance[$this->lastHandlerKey]->sql_affected_rows(); break; } return $output; } /** * Move internal result pointer * * @param pointer MySQL result pointer (of SELECT query) / DBAL object * @param integer Seek result number. * @return boolean Returns TRUE on success or FALSE on failure. */ function sql_data_seek(&$res,$seek) { $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; switch($handlerType) { case 'native': $output = mysql_data_seek($res,$seek); break; case 'adodb': $output = $res->Move($seek); break; case 'userdefined': $output = $res->sql_data_seek($seek); break; } return $output; } /** * Get the type of the specified field in a result * * If the first parameter is a string, it is used as table name for the lookup. * * @param pointer MySQL result pointer (of SELECT query) / DBAL object / table name * @param integer Field index. In case of ADOdb a string (field name!) FIXME * @return string Returns the type of the specified field index */ function sql_field_metatype($table,$field) { return $this->cache_fieldType[$table][$field]['metaType']; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -