function testFetchWithWrongSQL()
 {
     try {
         $rs = lmbDBAL::fetch($sql = 'SLECT 1=1');
         $this->fail();
     } catch (lmbDbException $e) {
         $this->assertPattern('/The result of this SQL query can not be fetched./', $e->getMessage());
         $this->assertEqual($e->getParam('query'), $sql);
     }
 }
 function testProcessPrefixedFieldsAsRelatedActiveRecords()
 {
     $course = $this->_createCourseWithTwoLectures();
     $lecture = new LectureForTest();
     $course_info = $lecture->getRelationInfo('course');
     $conn = lmbToolkit::instance()->getDefaultDbConnection();
     $db = new lmbSimpleDb($conn);
     $sql = 'SELECT ' . $conn->quoteIdentifier("lecture_for_test") . '.*, ' . $conn->quoteIdentifier("course_for_test.id") . ' as ' . $conn->quoteIdentifier("course__id") . ', ' . $conn->quoteIdentifier("course_for_test.title") . ' as ' . $conn->quoteIdentifier("course__title") . ' 
         FROM ' . $conn->quoteIdentifier("lecture_for_test") . ' LEFT JOIN ' . $conn->quoteIdentifier("course_for_test") . ' ON ' . $conn->quoteIdentifier("course_for_test.id") . ' = ' . $conn->quoteIdentifier("lecture_for_test.course_id");
     $decorated = lmbDBAL::fetch($sql);
     $iterator = new lmbARRecordSetJoinDecorator($decorated, new LectureForTest(), null, array('course' => $course_info));
     // let's fetch all data in order to actually call rewind() and current();
     $arr = $iterator->getArray();
     // now let's remove everything from db tables so we can be sure that processing is correct
     $db->delete('lecture_for_test');
     $db->delete('course_for_test');
     $this->assertEqual($arr[0]->get('course')->getTitle(), $course->getTitle());
     $this->assertEqual($arr[1]->get('course')->getTitle(), $course->getTitle());
 }
Exemple #3
0
    }
}
echo "native pgsql fetching: " . (microtime(true) - $mark) . "\n";
$conn = lmbDBAL::newConnection('pgsql://*****:*****@localhost/medkrug');
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $rs = lmbDBAL::fetch('SELECT bar FROM foo', $conn);
    foreach ($rs as $record) {
        $bar = $record['bar'];
    }
    $rs->freeQuery();
}
echo "lmbDBAL :: fetch(), array access: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $rs = lmbDBAL::fetch('SELECT bar FROM foo', $conn);
    foreach ($rs as $record) {
        $bar = $record->get('bar');
    }
    $rs->freeQuery();
}
echo "lmbDBAL :: fetch(), getter: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $stmt = $conn->newStatement('SELECT bar FROM foo');
    $rs = $stmt->getRecordSet();
    foreach ($rs as $record) {
        $bar = $record->get('bar');
    }
}
echo "lmbPgsqlConnection :: newStatement(), getter: " . (microtime(true) - $mark) . "\n";
Exemple #4
0
    }
}
echo "native linter fetching: " . (microtime(true) - $mark) . "\n";
$conn = lmbDBAL::newConnection('linter://*****:*****@localhost/Demo');
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $rs = lmbDBAL::fetch('SELECT "bar" FROM "foo";', $conn);
    foreach ($rs as $record) {
        $bar = $record['bar'];
    }
    $rs->freeQuery();
}
echo "lmbDBAL :: fetch(), array access: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $rs = lmbDBAL::fetch('SELECT "bar" FROM "foo";', $conn);
    foreach ($rs as $record) {
        $bar = $record->get('bar');
    }
    $rs->freeQuery();
}
echo "lmbDBAL :: fetch(), getter: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $stmt = $conn->newStatement('SELECT "bar" FROM "foo";');
    $rs = $stmt->getRecordSet();
    foreach ($rs as $record) {
        $bar = $record->get('bar');
    }
}
echo "lmbLinterConnection :: newStatement(), getter: " . (microtime(true) - $mark) . "\n";
 protected function _changeItemsPriority($model, $where_field, $where_field_value)
 {
     $priority_items = $this->request->get('priority_items');
     $info_item = new $model();
     $sql = 'SELECT id, priority FROM ' . $info_item->getTableName() . ' WHERE ' . $where_field . '=' . $where_field_value;
     $current_priorities_object = lmbDBAL::fetch($sql);
     $current_priorities_object = $current_priorities_object->getArray();
     $current_priorities = array();
     foreach ($current_priorities_object as $item) {
         $current_priorities[$item->get('id')] = $item->get('priority');
     }
     foreach ($priority_items as $id => $priority) {
         $current_priorities[$id] = $priority;
     }
     asort($current_priorities);
     $i = 10;
     $table_name = $info_item->getTableName();
     foreach ($current_priorities as $id => $priority) {
         $sql = "UPDATE " . $table_name . " SET priority='" . $i . "' WHERE id='" . $id . "'";
         lmbDBAL::execute($sql);
         $i += 10;
     }
 }