Commit 1a4c340b authored by Penny Leach's avatar Penny Leach
Browse files

beginnings of making mahara mysql compatible - escape reserved words

properly
parent 9edab31c
......@@ -83,6 +83,7 @@ try {
ob_start();
$db = &ADONewConnection($CFG->dbtype);
$dbgenerator = null;
if (!empty($CFG->dbport)) {
$CFG->dbhost .= ':'.$CFG->dbport;
}
......
......@@ -875,7 +875,7 @@ function delete_records_sql($sql, $values=null) {
* @throws SQLException
*/
function insert_record($table, $dataobject, $primarykey=false, $returnpk=false) {
global $db;
global $db, $dbgenerator;
static $table_columns;
// Determine all the fields in the table
......@@ -890,7 +890,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
if (!empty($primarykey)) {
unset($dataobject->{$primarykey});
if (!empty($returnpk)) {
if (!empty($returnpk) && is_postgres()) {
$pksql = "SELECT NEXTVAL('" . get_config('dbprefix') . "{$table}_{$primarykey}_seq')";
if ($nextval = (int)get_field_sql($pksql)) {
$setfromseq = true;
......@@ -919,7 +919,12 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
$values = '';
foreach ($ddd as $key => $value) {
$count++;
$fields .= $key;
if (in_array($key, $dbgenerator->reserved_words)) {
$fields .= '"' . $key . '"';
}
else {
$fields .= $key;
}
$values .= '?';
if ($count < $numddd) {
$fields .= ', ';
......@@ -1112,6 +1117,16 @@ function update_record($table, $dataobject, $where=null) {
* @param string $value3 the value field3 must have (requred if field3 is given, else optional).
*/
function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
global $dbgenerator;
if (in_array($field1, $dbgenerator->reserved_words)) {
$field1 = '"' . $field1 . '"';
}
if (in_array($field2, $dbgenerator->reserved_words)) {
$field2 = '"' . $field2 . '"';
}
if (in_array($field3, $dbgenerator->reserved_words)) {
$field3 = '"' . $field3 . '"';
}
if ($field1) {
$select = "WHERE $field1 = '$value1'";
if ($field2) {
......@@ -1136,6 +1151,16 @@ function where_clause($field1='', $value1='', $field2='', $value2='', $field3=''
* @private
*/
function where_clause_prepared($field1='', $field2='', $field3='') {
global $dbgenerator;
if (in_array($field1, $dbgenerator->reserved_words)) {
$field1 = '"' . $field1 . '"';
}
if (in_array($field2, $dbgenerator->reserved_words)) {
$field2 = '"' . $field2 . '"';
}
if (in_array($field3, $dbgenerator->reserved_words)) {
$field3 = '"' . $field3 . '"';
}
$select = '';
if (!empty($field1)) {
$select = " WHERE $field1 = ? ";
......@@ -1285,10 +1310,18 @@ function db_format_tsfield($field, $as = null) {
*/
function configure_dbconnection() {
global $db;
global $dbgenerator;
$classname = 'XMLDB' . get_config('dbtype');
$dbgenerator = new $classname();
increment_perf_db_writes();
$db->Execute("SET NAMES 'utf8'");
if (is_mysql()) {
$db->Execute("SET sql_mode='POSTGRESQL'");
}
// more later..
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment