Topic on Project:Village Pump

A database query error has occurred. This may indicate a bug in the software

2
196.36.226.1 (talkcontribs)

Recently received this error creating a new page.

The alias name for a field was not bracketed and the sequel server had a problem with this. Used the following code to change which resolved the issue.

The file : .\includes\db\Database.php

Before:

         
/**
              
* Get an aliased field name
* e.g. fieldName AS newFieldName
*
* @param string $name Field name
* @param string|bool $alias Alias (optional)
* @return string SQL name for aliased field. Will not alias a field to its own
name
*/

public function fieldNameWithAlias( $name, $alias = false ) {
                             
if ( !$alias || (string)$alias === (string)$name ) {
                                            
return $name;
                             
} else {
                                            
return $name . ' AS ' .
$alias; //PostgreSQL needs AS
                             
}
              
}

After:

              
/**
* Get an aliased field name
* e.g. fieldName AS newFieldName
*
* @param string $name Field name
* @param string|bool $alias Alias (optional)
* @return string SQL name for aliased field. Will not alias a field to its own
name
*/
              
public function fieldNameWithAlias( $name, $alias = false ) {
                             
if ( !$alias || (string)$alias === (string)$name ) {
                                            
return $name;
                             
} else {
                                            
return $name . ' AS [' .
$alias . ']'; //PostgreSQL needs AS
                             
}
              
}
Ciencia Al Poder (talkcontribs)
Reply to "A database query error has occurred. This may indicate a bug in the software"