18 import(
'lib.pkp.classes.xml.XMLParser');
51 $tree = $parser->parse($file);
52 if (!$tree)
return array();
54 $allTables = $this->dbconn->MetaTables();
55 foreach ($tree->getChildren() as $type)
switch($type->getName()) {
57 $fieldDefaultValues = array();
60 foreach ($type->getChildren() as $row) {
61 switch ($row->getName()) {
64 $fieldValues = array();
66 foreach ($row->getChildren() as $field) {
69 $fieldValues[$fieldName] = $value;
72 $fieldValues = array_merge($fieldDefaultValues, $fieldValues);
74 if (count($fieldValues) > 0) {
75 $this->sql[] = sprintf(
76 'INSERT INTO %s (%s) VALUES (%s)',
77 $type->getAttribute(
'name'),
78 join(
', ', array_keys($fieldValues)),
79 join(
', ', array_values($fieldValues)));
82 default: assert(
false);
88 foreach ($type->getChildren() as $child)
switch ($child->getName()) {
90 if (!isset($dbdict)) {
91 $dbdict = @NewDataDictionary($this->dbconn);
93 $table = $child->getAttribute(
'table');
94 $column = $child->getAttribute(
'column');
97 $this->sql[] = $dbdict->DropColumnSql($table, $column);
99 $this->sql[] = $dbdict->DropTableSQL($table);
103 if (!isset($dbdict)) {
104 $dbdict = @NewDataDictionary($this->dbconn);
106 $table = $child->getAttribute(
'table');
107 $column = $child->getAttribute(
'column');
108 $to = $child->getAttribute(
'to');
113 if (in_array($table, $allTables)) {
114 $columns = $this->dbconn->MetaColumns($table,
true);
115 if (!isset($columns[strtoupper($to)])) {
128 $colId = strtoupper($column);
130 if (isset($columns[$colId])) {
131 $col = $columns[$colId];
132 if ($col->max_length ==
"-1") {
135 $max_length = $col->max_length;
137 $fld = array(
'NAME' => $col->name,
'TYPE' => $dbdict->MetaType($col),
'SIZE' => $max_length);
138 if ($col->primary_key) $fld[
'KEY'] =
'KEY';
139 if ($col->auto_increment) $fld[
'AUTOINCREMENT'] =
'AUTOINCREMENT';
140 if ($col->not_null) $fld[
'NOTNULL'] =
'NOTNULL';
141 if ($col->has_default) $fld[
'DEFAULT'] = $col->default_value;
142 $flds = array($colId => $fld);
143 }
else assert(
false);
145 $this->sql[] = $dbdict->RenameColumnSQL($table, $column, $to, $flds);
150 if (!in_array($to, $allTables)) {
151 $this->sql[] = $dbdict->RenameTableSQL($table, $to);
156 if (!isset($dbdict)) {
157 $dbdict = @NewDataDictionary($this->dbconn);
159 $table = $child->getAttribute(
'table');
160 $index = $child->getAttribute(
'index');
161 if (!$table || !$index) {
162 throw new Exception(
'dropindex called without table or index');
164 $indexes = array_map(
'strtoupper', array_keys($this->dbconn->MetaIndexes($table)));
165 if (in_array(strtoupper($index), $indexes)) {
166 $this->sql[] = $dbdict->DropIndexSQL($index, $table);
172 $driver = $child->getAttribute(
'driver');
173 if (empty($driver) || in_array($this->dbconn->databaseType, array_map(
'trim', explode(
',', $driver)))) {
174 $this->sql[] = $child->getValue();
189 $this->errorMsg =
null;
191 foreach ($this->sql as $stmt) {
193 if (!$continueOnError &&
$dbconn->errorNo() != 0) {
214 return $this->dbconn->qstr($str);
228 $fieldName = $fieldNode->getAttribute(
'name');
229 $fieldValue = $fieldNode->getValue();
233 $isEmpty = $fieldNode->getAttribute(
'null');
234 if (!is_null($isEmpty)) {
235 assert(is_null($fieldValue));
248 if (is_null($fieldValue)) {
249 $fieldValue =
'NULL';
252 if (!is_numeric($fieldValue)) {
257 return array($fieldName, $fieldValue);