Пример #1
0
function init_env($time)
{
    chdir("/home/crowler/");
    init_db();
    $symbols = find_symbols_list();
    add_debug($time);
    return $symbols;
}
Пример #2
0
function drop_trigger($name)
{
    global $s_triggers, $dbhandle, $ib_error;
    global $lsql;
    $lsql = 'DROP TRIGGER ' . $name;
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
    } else {
        unset($s_triggers[$name]);
    }
}
function create_procedure($proceduredefs)
{
    global $s_login, $isql, $binary_output, $binary_error;
    if (empty($proceduredefs['source'])) {
        return FALSE;
    }
    $isql = "SET TERM !! ;\n" . $proceduredefs['source'] . "\n" . "SET TERM ; !!\n";
    if (DEBUG) {
        add_debug('isql', __FILE__, __LINE__);
    }
    // this must be done by isql because 'create procedure' is not supported from within php
    list($binary_output, $binary_error) = isql_execute($isql, $s_login['user'], $s_login['password'], $s_login['database'], $s_login['host']);
    return $binary_error != '' || count($binary_output) > 0 ? FALSE : TRUE;
}
Пример #4
0
function drop_view($name)
{
    global $dbhandle, $s_tables;
    global $ib_error, $lsql;
    $lsql = 'DROP VIEW ' . $name;
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
        return FALSE;
    } else {
        unset($s_tables[$name]);
        return TRUE;
    }
}
Пример #5
0
function revoke_role_from_user($role, $user)
{
    global $dbhandle, $roles;
    global $ib_error, $lsql;
    $user = strtoupper($user);
    $lsql = 'REVOKE ' . $role . ' FROM ' . $user;
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
    }
    if (empty($ib_error) && ($idx = array_search($user, $roles[$role]['members'])) !== FALSE) {
        unset($roles[$role]['members'][$idx]);
        return TRUE;
    } else {
        return FALSE;
    }
}
Пример #6
0
function drop_udf($name)
{
    global $s_udfs, $dbhandle;
    global $ib_error, $lsql;
    $lsql = 'DROP EXTERNAL FUNCTION ' . $name;
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
        return FALSE;
    } else {
        unset($s_udfs[$name]);
        return TRUE;
    }
}
function insert_row($table, $cols, $values)
{
    $quote = identifier_quote($GLOBALS['s_login']['dialect']);
    $sql = 'INSERT INTO ' . $quote . $table . $quote . ' (' . $quote . implode($quote . ', ' . $quote, $cols) . $quote . ')' . ' VALUES (' . substr(str_repeat('?, ', count($values)), 0, -2) . ')';
    if (DEBUG) {
        add_debug('$sql: ' . $sql, __FILE__, __LINE__);
    }
    $query = fbird_prepare($GLOBALS['dbhandle'], $sql) or ib_error(__FILE__, __LINE__, $sql);
    $ib_error = '';
    call_user_func_array('fbird_execute', array_merge(array($query), $values)) or $ib_error = fbird_errmsg();
    fbird_free_query($query);
    return $ib_error;
}
Пример #8
0
function export_data($export)
{
    global $s_fields, $warning;
    ini_set('ibase.dateformat', $export['general']['date']);
    ini_set('ibase.timeformat', $export['general']['time']);
    ini_set('ibase.timestampformat', $export['general']['date'] . ' ' . $export['general']['time']);
    if ($export['format'] == 'sql' && $export['sql']['info']) {
        echo sql_export_info($export, replace_escape_sequences($export['sql']['lineend']));
    }
    foreach (export_queries($export) as $query) {
        if (DEBUG) {
            add_debug($query, __FILE__, __LINE__);
        }
        $trans = fbird_trans(TRANS_READ, $dbhandle);
        $res = @fbird_query($trans, $query);
        if ($res === FALSE) {
            $ib_error = fbird_errmsg();
            $warning = '';
            return FALSE;
        }
        $columns = $col_types = $num_fields = array();
        $num = fbird_num_fields($res);
        for ($idx = 0; $idx < $num; $idx++) {
            $info = fbird_field_info($res, $idx);
            $columns[] = $info['name'];
            $col_types[] = $info['type'];
            $num_fields[] = is_number_type(substr($info['type'], 0, strcspn($info['type'], '(')));
        }
        $tablename = $info['relation'];
        $export['query'] = array('source' => $query, 'columns' => $columns, 'col_types' => $col_types, 'num_fields' => $num_fields, 'result' => $res);
        switch ($export['format']) {
            case 'csv':
                export_csv_data($export);
                break;
            case 'sql':
                export_sql_data($export, $tablename);
                break;
            case 'ext':
                printf('Export data to %s is still not implemented!', $export['format']);
                break;
            default:
                echo 'Unsupported export format!';
        }
        fbird_free_result($res);
        fbird_commit($trans);
    }
}
Пример #9
0
function modify_domain($olddef, $domdef)
{
    global $dbhandle, $ib_error;
    $lsql = array();
    if ($domdef['name'] != $olddef['name']) {
        $lsql[] = 'ALTER DOMAIN ' . $olddef['name'] . ' TO ' . $domdef['name'];
    }
    if (datatype_is_modified($olddef, $domdef)) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' TYPE ' . build_datatype($domdef);
    }
    if (isset($olddef['default']) && $olddef['default'] != '' && $domdef['default'] == '') {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' DROP DEFAULT';
    }
    if (isset($olddef['default']) && $domdef['default'] != '' && $olddef['default'] != $domdef['default']) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' SET DEFAULT ' . $domdef['default'];
    }
    if (isset($olddef['check']) && !empty($olddef['check']) && (empty($domdef['check']) || $olddef['check'] != $domdef['check'])) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' DROP CONSTRAINT';
    }
    if (isset($olddef['check']) && $olddef['check'] != $domdef['check']) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' ADD CHECK ' . $domdef['check'];
    }
    foreach ($lsql as $sql) {
        if (DEBUG) {
            add_debug($sql, __FILE__, __LINE__);
        }
        if (!@fbird_query($dbhandle, $sql)) {
            $ib_error = fbird_errmsg() . "<br>\n>";
            return FALSE;
        }
    }
    return TRUE;
}
Пример #10
0
function drop_index($name)
{
    global $indices, $dbhandle, $ib_error, $lsql;
    $lsql = 'DROP INDEX ' . $name;
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
        return TRUE;
    } else {
        unset($indices[$name]);
        return TRUE;
    }
}
Пример #11
0
 /**
         Get($varID, $cacheLife) --
         Retrives the value inside a cache file
         specified by $varID if the expiration time
         (specified by $cacheLife) is not over.
         If expired, returns FALSE
 	 **/
 function Get($varId, $cacheLife = "")
 {
     global $config;
     // 设置默认缓存周期
     //$cacheLife = (! empty ( $cacheLife )) ? $cacheLife : $this->defaultCacheLife;
     if ($cacheLife !== false && $cacheLife != '0' && !is_numeric($cacheLife)) {
         $cacheLife = $this->defaultCacheLife;
     }
     if ($cacheLife == 0) {
         $cacheLife = false;
     }
     /* 循环查找缓存文件 */
     /* $dirHandler = dir($this->cacheDir);
             while ($file = $dirHandler->read()) {
                 /* 用请求的变量ID查找缓存文件 * /
                 if (preg_match("/cache.$varId.[0-9]/", $file)) {
                     $cacheFileName = explode(".", $file);
                     // 缓存文件创建时间
                     $cacheFileLife = $cacheFileName[2];
                     // 完整存放位置
                     $cacheFile = $this->cacheDir . $file;
     
                     /* 检查缓存文件是否过期 * /
                     if ( $cacheLife == 0 || (time() - $cacheFileLife) <= $cacheLife) {
                         $fileHandler = fopen($cacheFile, "r");
                         $varValueResult = fread($fileHandler, filesize($cacheFile));
                         fclose($fileHandler);
                         // 未过期则返回为序列化的数据
                         return unserialize($varValueResult);
                     } else {
                         // 缓存过期,终止循环
                         break;
                     }
                 }
             }
             $dirHandler->close();
             */
     $file = $this->cacheDir . "cache." . $varId;
     //echo '<br />';
     if (file_exists($file) && filesize($file) > 0) {
         if ($cacheLife === false || time() - filemtime($file) <= $cacheLife) {
             $fileHandler = fopen($file, "r");
             $varValueResult = fread($fileHandler, filesize($file));
             fclose($fileHandler);
             // 未过期则返回为序列化的数据
             return unserialize($varValueResult);
         } else {
             if ($config['debug'] == 1) {
                 //add_debug ( "cache expire: " . $varId . " TimeExpire: " . unix_time ( filectime ( $file ) ) );
             }
             return false;
         }
     } else {
         if ($config['debug'] == 1) {
             add_debug("cache file not exists! " . $varId);
         }
         return false;
     }
     return FALSE;
 }
Пример #12
0
}
// deleting a subject is confirmed
if (isset($_POST['confirm_yes']) && isset($s_confirmations[$_POST['confirm_subject']])) {
    $sql = $s_confirmations[$_POST['confirm_subject']]['sql'];
    unset($s_confirmations[$_POST['confirm_subject']]);
}
// deleting a subject is canceled
if (isset($_POST['confirm_no']) && isset($s_confirmations[$_POST['confirm_subject']])) {
    unset($s_confirmations[$_POST['confirm_subject']]);
}
//
// perform the sql-statement in $sql
//
if ($sql != '') {
    if (DEBUG) {
        add_debug('$sql: ' . $sql, __FILE__, __LINE__);
    }
    $trans = fbird_trans(TRANS_WRITE, $dbhandle);
    if (fbird_query($trans, $sql)) {
        fbird_commit($trans);
        $s_tables_valid = FALSE;
        $s_create_table = '';
        $s_create_num = 0;
        $s_coldefs = array();
        $s_modify_col = '';
    } else {
        $ib_error = fbird_errmsg();
        fbird_rollback($trans);
        if (isset($mod_flag) && $mod_flag == TRUE) {
            $col_mod_flag = TRUE;
        }