Project

General

Profile

Feature #14338 » 0000390-class.t3lib_db.php.diff

Administrator Admin, 2004-09-28 01:14

View differences:

t3lib/class.t3lib_db.php 2004-09-28 01:10:54.000000000 +0200
// Default link identifier:
var $link;
var $table_prefix='test_'; // If not empty, this will be used as table prefix
......
* @depreciated use exec_INSERTquery() instead if possible!
*/
function INSERTquery($table,$fields_values) {
$table = $this->tablePrefix($table,0,1);
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
if (is_array($fields_values) && count($fields_values)) {
......
* @depreciated use exec_UPDATEquery() instead if possible!
*/
function UPDATEquery($table,$where,$fields_values) {
$table = $this->tablePrefix($table);
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
if (is_string($where)) {
......
* @depreciated use exec_DELETEquery() instead if possible!
*/
function DELETEquery($table,$where) {
$table = $this->tablePrefix($table,0,1);
if (is_string($where)) {
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
......
* @depreciated use exec_SELECTquery() instead if possible!
*/
function SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') {
$from_table = $this->tablePrefix($from_table);
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
// Build basic query:
......
* @return string Output string; Quotes (" / ') and \ will be backslashed (or otherwise based on DBAL handler)
*/
function quoteStr($str, $table) {
$table = $this->tablePrefix($table);
return addslashes($str);
}
......
$tables_result = mysql_list_tables(TYPO3_db, $this->link);
if (!mysql_error()) {
while ($theTable = mysql_fetch_assoc($tables_result)) {
$theTable[key($theTable)]=$this->tablePrefix(current($theTable),1);
$whichTables[current($theTable)] = current($theTable);
}
}
......
* @return array Field information in an associative array with fieldname => field row
*/
function admin_get_fields($tableName) {
$tableName = $this->tablePrefix($tableName);
$output = array();
$columns_res = mysql_query('SHOW columns FROM '.$tableName, $this->link);
......
* @return array Key information in a numeric array
*/
function admin_get_keys($tableName) {
$tableName = $this->tablePrefix($tableName);
$output = array();
$keyRes = mysql_query('SHOW keys FROM '.$tableName, $this->link);
......
/**
* Optionally, add a prefix to each table name
*
* @param string Name of the table that needs to be prefixed. Comma-separated lists are allowed.
* @param boolean True if the prefix needs to be removed instead
* @param boolean If false, the alias is not set for a table name
* @return string The input string with added/removed tablePrefix
*/
function tablePrefix($table,$removePrefix=0,$doNotAddAlias=0) {
if(!$removePrefix) { // Add the prefix
if(ereg(',',$table)) {
// Looks like a list of multiple tables. Split it and add the prefix to every table
$tmpArr=array();
foreach(t3lib_div::trimExplode(',',$table) as $table) {
if(ereg(' AS ',$table)) $tmpArr[]=$this->tablePrefix($table,0,1);
else $tmpArr[]=$this->tablePrefix($table,0,1).' AS '.$table;
}
// Change the array back into a comma separated list
$table=implode(',',$tmpArr);
} else {
// Add the prefix if it is not prepended yet
if(!ereg("^".$this->table_prefix, $table)) {
if($doNotAddAlias || ereg(' AS ',$table)) $table=$this->table_prefix.$table;
else $table=$this->table_prefix.$table.' AS '.$table;
}
}
} else { // Remove the prefix
if(ereg("^".$this->table_prefix, $table)) $table = ereg_replace("^".$this->table_prefix."(.*)", "\\1", $table);
}
return $table;
}
(1-1/3)