Permalink
Browse files

BUGFIX: Handling of classes with namespaces in database

MySQLDatabase::enumValuesForField() - Added stripslashes because backslashes are escaped in the type description

DataObject::requireTable() - Added double quotes to column names in automatically generated indexes for many_many relationships

DataObject::write() - Escaped class name for DB query

DataQuery::getFinalisedQuery() - Escaped class names for DB query
  • Loading branch information...
1 parent 9898cd9 commit ec554689325765881a83df6f87c34efe80c92961 @schmengler schmengler committed Jun 2, 2012
Showing with 6 additions and 4 deletions.
  1. +3 −3 model/DataObject.php
  2. +2 −0 model/DataQuery.php
  3. +1 −1 model/MySQLDatabase.php
View
@@ -1131,7 +1131,7 @@ public function write($showDebug = false, $forceInsert = false, $forceWrite = fa
if($dbCommand == 'insert') {
$manipulation[$class]['fields']["Created"] = "'".SS_Datetime::now()->Rfc2822()."'";
//echo "<li>$this->class - " .get_class($this);
- $manipulation[$class]['fields']["ClassName"] = "'$this->class'";
+ $manipulation[$class]['fields']["ClassName"] = DB::getConn()->prepStringForDB($this->class);
}
}
@@ -2942,8 +2942,8 @@ public function requireTable() {
// Build index list
$manymanyIndexes = array(
- "{$this->class}ID" => true,
- (($this->class == $childClass) ? "ChildID" : "{$childClass}ID") => true,
+ "\"{$this->class}ID\"" => true,
+ (($this->class == $childClass) ? "ChildID" : "\"{$childClass}ID\"") => true,
);
DB::requireTable("{$this->class}_$relationship", $manymanyFields, $manymanyIndexes, true, null, $extensions);
View
@@ -198,6 +198,7 @@ function getFinalisedQuery($queriedColumns = null) {
if(preg_match('/^"([^"]+)"/', $collision, $matches)) {
$collisionBase = $matches[1];
$collisionClasses = ClassInfo::subclassesFor($collisionBase);
+ $collisionClasses = array_map(array(DB::getConn(), 'prepStringForDB'), $collisionClasses);
$caseClauses[] = "WHEN \"$baseClass\".\"ClassName\" IN ('"
. implode("', '", $collisionClasses) . "') THEN $collision";
} else {
@@ -215,6 +216,7 @@ function getFinalisedQuery($queriedColumns = null) {
// Get the ClassName values to filter to
$classNames = ClassInfo::subclassesFor($this->dataClass);
if(!$classNames) user_error("DataList::create() Can't find data sub-classes for '$callerClass'");
+ $classNames = array_map(array(DB::getConn(), 'prepStringForDB'), $classNames);
$query->addWhere("\"$baseClass\".\"ClassName\" IN ('" . implode("','", $classNames) . "')");
}
}
View
@@ -776,7 +776,7 @@ public function enumValuesForField($tableName, $fieldName) {
$classes = array();
foreach($matches[0] as $value) {
- $classes[] = trim($value, "'");
+ $classes[] = stripslashes(trim($value, "'"));
}
return $classes;
}

0 comments on commit ec55468

Please sign in to comment.