Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always name quote #209

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions adodb-datadict.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,13 @@ function NameQuote($name = NULL,$allowBrackets=false)
return $quote . $matches[1] . $quote;
}

// if name contains special characters, quote it
$regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex;

if ( !preg_match('/^[' . $regex . ']+$/', $name) ) {
return $quote . $name . $quote;
// allways quote column names to kope with column names being reserved words like eg. "timestamp"
// if brackets are allowed, quote only the rest,
// to allow to limit indexes on colums, eg "column(32)"
if ($allowBrackets && preg_match('/^(.*) *(\(\d+\))$/',$name,$matches)) {
return $quote . $matches[1] . $quote . ' '. $matches[2];
}

return $name;
return $quote . $name . $quote;
}

function TableName($name)
Expand Down Expand Up @@ -665,11 +664,11 @@ function _GenFields($flds,$widespacing=false)
//-----------------
// Parse attributes
foreach($fld as $attr => $v) {
if ($attr == 2 && is_numeric($v))
if ($attr == 2 && is_numeric($v))
$attr = 'SIZE';
elseif ($attr == 2 && strtoupper($ftype) == 'ENUM')
elseif ($attr == 2 && strtoupper($ftype) == 'ENUM')
$attr = 'ENUM';
else if (is_numeric($attr) && $attr > 1 && !is_numeric($v))
else if (is_numeric($attr) && $attr > 1 && !is_numeric($v))
$attr = strtoupper($v);

switch($attr) {
Expand Down Expand Up @@ -820,7 +819,7 @@ function _GetSize($ftype, $ty, $fsize, $fprec, $options=false)
if (strlen($fprec)) $ftype .= ",".$fprec;
$ftype .= ')';
}

/*
* Handle additional options
*/
Expand All @@ -833,12 +832,12 @@ function _GetSize($ftype, $ty, $fsize, $fprec, $options=false)
case 'ENUM':
$ftype .= '(' . $value . ')';
break;

default:
}
}
}

return $ftype;
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/adodb-mysqli.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ function MetaColumns($table, $normalize=true)
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false)
$savem = $this->SetFetchMode(false);
// need to remove quotes, if table-name is already name-quoted by datadict::MetaColumns
if ($table[0] == $this->nameQuote) $table = substr($table, 1, -1);
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
Expand Down
8 changes: 8 additions & 0 deletions drivers/adodb-postgres64.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ function MetaColumns($table,$normalize=true)
{
global $ADODB_FETCH_MODE;

// table-name must NOT be quoted, otherwise we will not find any index
$table = str_replace($this->nameQuote,'',$table);

$schema = false;
$false = false;
$this->_findschema($table,$schema);
Expand Down Expand Up @@ -616,6 +619,11 @@ function MetaIndexes ($table, $primary = FALSE, $owner = false)
{
global $ADODB_FETCH_MODE;

//if tablenames are quoted, remove the quotes as the tablenames here are used for comparsion of content of fields in postgres system tables
if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) {
$table = str_replace($this->nameQuote,'',$table);
}

$schema = false;
$this->_findschema($table,$schema);

Expand Down