function testExecuteUsingDefaultConnection()
 {
     $this->toolkit->setDefaultDbConnection($this->conn);
     $this->conn->expectOnce('execute', array($sql = 'SELECT 1=1'));
     lmbDBAL::execute('SELECT 1=1');
 }
 protected function _createRootElementIfNotExists()
 {
     if (!($root = lmbDBAL::fetchOneRow('SELECT * FROM ' . $this->_table->getName()))) {
         lmbDBAL::execute('INSERT INTO ' . $this->_table->getName() . ' (parent_id, level, priority, is_published, path, identifier, ctime, utime) VALUES (0,0,0,0,\'/1/\',\'\',0,0)');
     }
 }
Exemple #3
0
/**
 * @desc create db by specified DSN
 * @deps project_db_init_config
 * @example project.php create_db -D DSN=mysqli://root:test@localhost/limb_app?charset=utf8
 */
function task_project_db_create($args)
{
    lmb_package_require('dbal');
    lmb_require('limb/dbal/src/lmbDbDSN.class.php');
    $code = <<<EOD
    \$toolkit = lmbToolkit :: instance();
    echo \$toolkit->getDefaultDbDSN()->toString();
EOD;
    $output = lmb_cli_run_code_in_project_env($code);
    $dsn = new lmbDbDSN($output);
    $db_name = $dsn->database;
    $dsn->database = false;
    $conn = lmbToolkit::instance()->createDbConnection($dsn);
    lmbDBAL::execute('CREATE DATABASE ' . $conn->quoteIdentifier($db_name), $conn);
    taskman_msg("Database ({$db_name}) created...\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;
     }
 }