Menu

#5 Table name "quotes" for MSSQL

open
nobody
None
5
2005-04-18
2005-04-18
Alex King
No

My CREATE statements were all failing until I set the
$nameQuote value to empty string.

Discussion

  • Alex King

    Alex King - 2005-04-18
     
  • Andrew Eddie

    Andrew Eddie - 2005-06-20

    Logged In: YES
    user_id=507145

    Yes, I came across this too. Particularly annoying in
    MS-SQL. My solution was to extend my own db connector with
    this function:

    /**
    * Quote an identifier name (field, table, etc)
    * @param string The name
    * @return string The quoted name
    */
    function NameQuote( $s ) {
    $q = $this->_resource->nameQuote;
    if (strlen( $q ) == 1) {
    return $q . $s . $q;
    } else {
    return $q{0} . $s . $q{1};
    }
    }

    Where _resource is the ADO connection object and for MS-SQL
    I defined the nameQuote as '[]'

     
  • Clifton

    Clifton - 2005-10-25

    Logged In: YES
    user_id=1366626

    a better fix for this is:
    // mysqli defines as is:

    var $nameQuote = '`';

    // mssql can't use this, so:

    var $nameQuote = array('[',']');

    // So, when $db->nameQuote is being used to quote column
    names:

    if (!isset($zthis->nameQuote)) $zthis->nameQuote="";

    if ( is_array($zthis->nameQuote) )
    list($lq, $rq) = $zthis->nameQuote;
    else
    $lq = $rq = $zthis->nameQuote;

    $fnameq = $lq.$upperfname.$rq;

    //as all fields should be delimited to protect reserved word
    columns.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.