Ejemplo n.º 1
0
 /**
  *
  * read some test data from a resource (file)
  *
  * return a dataset array in 'text' mode
  * insert data in mysql db in 'insert' mode
  *
  * @todo get 'text' mode working
  * @todo consider separating the two modes into separate methods
  * @param string $source A filename
  * @param string $mode Either 'insert' or 'text'
  * @return void
  */
 static function loadDataSQL($source, $mode)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     $aDataset = TestEnv::getDataSQL($source, $mode);
     if ($aDataset) {
         foreach ($aDataset as $k => $v) {
             switch ($mode) {
                 case 'insert':
                     $oDbh =& OA_DB::singleton();
                     $query = '';
                     if (preg_match('/INSERT INTO (?P<table>[\\w\\W]+) (?P<query>\\([\\w\\W\\s]+\\);)/U', $v, $aMatches)) {
                         $table = $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aMatches['table'], true);
                         $query = 'INSERT INTO ' . $table . ' ' . $aMatches['query'];
                     }
                     $res = $oDbh->query($query);
                     if (!$res || PEAR::isError($res)) {
                         MAX::raiseError($res);
                         return;
                     }
                     break;
                 case 'text':
                     // XXX: Why do we return the first key in the dataset?
                     return $aDataset;
                     break;
             }
         }
         return;
     }
     MAX::raiseError('loadDataSQL error: unable to open ' . $source);
     return;
 }