Example #1
0
 /**
  * Handles opening elements of the xml file.
  */
 public function startElement($name, $attributes)
 {
     try {
         if ($name == "dataset") {
             // Clear any start/end DLL
             call_user_func(array($this->builderClazz, 'reset'));
             $this->sqlWriter->write(call_user_func(array($this->builderClazz, 'getDatabaseStartSql')));
         } else {
             // we're processing a row of data
             // where tag name is phpName e.g. <BookReader .... />
             $table = $this->database->getTableByPhpName($name);
             $columnValues = array();
             foreach ($attributes as $name => $value) {
                 $col = $table->getColumnByPhpName($name);
                 $columnValues[] = new ColumnValue($col, iconv('utf-8', $this->encoding, $value));
             }
             $data = new DataRow($table, $columnValues);
             if ($this->currTableName !== $table->getName()) {
                 // new table encountered
                 if ($this->currBuilder !== null) {
                     $this->sqlWriter->write($this->currBuilder->getTableEndSql());
                 }
                 $this->currTableName = $table->getName();
                 $this->currBuilder = $this->generatorConfig->getConfiguredBuilder($table, 'datasql');
                 $this->sqlWriter->write($this->currBuilder->getTableStartSql());
             }
             // Write the SQL
             $this->sqlWriter->write($this->currBuilder->buildRowSql($data));
         }
     } catch (Exception $e) {
         // Exceptions have traditionally not bubbled up nicely from the expat parser,
         // so we also print the stack trace here.
         print $e;
         throw $e;
     }
 }