コード例 #1
0
 function import($request)
 {
     $result = false;
     $file = $request->postVar('importfile');
     if (!empty($file['tmp_name'])) {
         $importtype = $request->postVar('importtype');
         if ($importtype == 'auto') {
             $importtype = strtolower(substr($file['name'], -3) == '.gz') ? 'compressedsql' : 'rawsql';
         }
         switch ($importtype) {
             case 'rawsql':
                 $result = new ArrayData(DBP_Sql::execute_script(file($file['tmp_name'])));
                 break;
             case 'compressedsql':
                 $result = new ArrayData(DBP_Sql::execute_script(gzfile($file['tmp_name'])));
                 break;
         }
     }
     return $result ? $result->renderWith('DBP_Database_sql') : $this->instance->customise(array('Message' => array('type' => 'error', 'text' => 'Your file could not be imported. You might want to check if the file size exceeds ' . $this->instance->MaxFileSize() . ' which is the limit set in post_max_size and upload_max_filesize in your php.ini.')))->renderWith('DBP_Database_sql');
 }
コード例 #2
0
 function testExecuteScriptWithRollback()
 {
     // skip if adapter doesn't support transactions
     if (!DB::getConn()->supportsTransactions()) {
         return;
     }
     // mixed commands, with errors and rollback
     $script = "\r\n\t\t\tINSERT INTO \"SiteTree\" (\"Title\", \"Content\") VALUES ('DBPRollbackTest', '<p>This should be gone after rollback.</p>');\r\n\t\t\tforce error;\r\n\t\t\tUPDATE \"SiteTree\" SET \"URLSegment\" = 'rollback-1' WHERE \"Title\" = 'DBPRollbackTest';\r\n\t\t";
     $result = DBP_Sql::execute_script($script);
     $this->assertType('array', $result, 'Result is array');
     $this->assertEquals('INSERT', substr($result['Query'], 0, 6), 'Return command');
     $this->assertEquals('error', $result['Message']['type'], 'Return message with error');
     $this->assertStringEndsWith('Transaction rolled back', $result['Message']['text'], 'Message states transaction state');
     $this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"SiteTree\" WHERE \"Title\" = 'DBPRollbackTest'")->Value(), 'Make sure the transaction really got rolled back');
 }