Exemplo n.º 1
0
function dbInsert($data, $table)
{
    global $fullSql, $database_link;
    global $db_stats;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE);
    }
    $sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`)  VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
    $time_start = microtime(true);
    dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        $id = mysqli_insert_id($database_link);
        dbCommitTransaction();
        // return $id;
    } else {
        if ($table != 'Contact') {
            trigger_error('QDB - Insert failed.', E_USER_WARNING);
        }
        dbRollbackTransaction();
        // $id = false;
    }
    // logfile($fullSql);
    $time_end = microtime(true);
    $db_stats['insert_sec'] += number_format($time_end - $time_start, 8);
    $db_stats['insert']++;
    return $id;
}
Exemplo n.º 2
0
function dbInsert($data, $table)
{
    global $fullSql;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        //trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE);
    }
    $sql = 'insert into ' . $table . ' (' . implode(',', array_keys($data)) . ') values(' . implode(',', dbPlaceHolders($data)) . ')';
    dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        $id = mysql_insert_id();
        dbCommitTransaction();
        return $id;
    } else {
        if ($table != 'Contact') {
            trigger_error('QDB - Insert failed.', E_WARNING);
        }
        dbRollbackTransaction();
        return false;
    }
}
Exemplo n.º 3
0
function update_db_table($tablename, $columns, $numkeys, $rows)
{
    dbBeginTransaction();
    foreach ($rows as $nothing => $obj) {
        // create a parameter list based on the columns
        $params = array();
        foreach ($columns as $column) {
            $params[] = $obj[$column];
        }
        $column_placeholders = array_fill(0, count($columns), '?');
        // build the "ON DUPLICATE KEY" part
        $non_key_columns = array_slice($columns, $numkeys);
        $non_key_placeholders = array_slice($column_placeholders, $numkeys);
        $update_definitions = array_map("join_array", $non_key_columns, $non_key_placeholders);
        $non_key_params = array_slice($params, $numkeys);
        $sql = 'INSERT INTO `' . $tablename . '` (' . implode(',', array_map("quote_column", $columns)) . ') VALUES (' . implode(',', $column_placeholders) . ') ON DUPLICATE KEY UPDATE ' . implode(',', $update_definitions);
        $result = dbQuery($sql, array_merge($params, $non_key_params));
        d_echo("Result: {$result}\n");
    }
    dbCommitTransaction();
}
                    // Process processRules first, because the ExecEngine may execute code while processing this stuff.
                    echo '<div id="ProcessRuleResults">';
                    checkRoleRules($selectedRoleNr);
                    echo '</div>';
                    // Run all stored procedures in the database
                    // Doing so AFTER running the ExecEngine allows any problems with stored procedures to be 'fixed'
                    // 2do this: create a rule with the same ruleexpression and handle the violation with th ExecEngine
                    runAllProcedures();
                    runAllProcedures();
                    echo '<div id="InvariantRuleResults">';
                    $invariantRulesHold = checkInvariantRules();
                    echo '</div>';
                    if ($invariantRulesHold) {
                        setTimeStamp();
                        emitLog("COMMIT");
                        dbCommitTransaction();
                    } else {
                        emitLog("ROLLBACK");
                        dbRollbackTransaction();
                    }
                    echo '</div>';
                }
            }
        }
    }
}
SetSMF('pause', false);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function processCommands()
{
    $commandsJson = $_POST['commands'];