function SetupDatabase(&$arguments)
 {
     if (isset($arguments["Connection"]) && strlen($error = MetabaseParseConnectionArguments($arguments["Connection"], $arguments))) {
         return $error;
     }
     if (isset($arguments["Debug"])) {
         $this->debug = $arguments["Debug"];
     }
     if (strlen($error = MetabaseSetupDatabase($arguments, $this->database))) {
         return $error;
     }
     if (!isset($arguments["Debug"])) {
         MetabaseCaptureDebugOutput($this->database, 1);
     }
     return "";
 }
function MetabaseSetupInterface(&$arguments, &$db)
{
    if (isset($arguments["Connection"]) && strlen($error = MetabaseParseConnectionArguments($arguments["Connection"], $arguments))) {
        return $error;
    }
    if (isset($arguments["Type"])) {
        if (GetType($dash = strpos($arguments["Type"], "-")) == "integer") {
            $type = substr($arguments["Type"], 0, $dash);
            $sub_type = substr($arguments["Type"], $dash + 1);
        } else {
            $type = $arguments["Type"];
            $sub_type = "";
        }
    } else {
        $type = $sub_type = "";
    }
    $sub_include = $sub_included = "";
    switch ($type) {
        case "ibase":
            $include = "metabase_ibase.php";
            $class_name = "metabase_ibase_class";
            $included = "METABASE_IBASE_INCLUDED";
            break;
        case "ifx":
            $include = "metabase_ifx.php";
            $class_name = "metabase_ifx_class";
            $included = "METABASE_IFX_INCLUDED";
            break;
        case "msql":
            $include = "metabase_msql.php";
            $class_name = "metabase_msql_class";
            $included = "METABASE_MSQL_INCLUDED";
            break;
        case "mssql":
            $include = "metabase_mssql.php";
            $class_name = "metabase_mssql_class";
            $included = "METABASE_MSSQL_INCLUDED";
            break;
        case "mysql":
            $include = "metabase_mysql.php";
            $class_name = "metabase_mysql_class";
            $included = "METABASE_MYSQL_INCLUDED";
            break;
        case "pgsql":
            $include = "metabase_pgsql.php";
            $class_name = "metabase_pgsql_class";
            $included = "METABASE_PGSQL_INCLUDED";
            break;
        case "odbc":
            $include = "metabase_odbc.php";
            $class_name = "metabase_odbc_class";
            $included = "METABASE_ODBC_INCLUDED";
            switch ($sub_type) {
                case "":
                    break;
                case "msaccess":
                    $sub_include = "metabase_odbc_msaccess.php";
                    $class_name = "metabase_odbc_msaccess_class";
                    $sub_included = "METABASE_ODBC_MSACCESS_INCLUDED";
                    break;
                default:
                    return "\"{$sub_type}\" is not a supported ODBC database sub type";
            }
            break;
        case "oci":
            $include = "metabase_oci.php";
            $class_name = "metabase_oci_class";
            $included = "METABASE_OCI_INCLUDED";
            break;
        case "sqlite":
            $include = "metabase_sqlite.php";
            $class_name = "metabase_sqlite_class";
            $included = "METABASE_SQLITE_INCLUDED";
            break;
        case "":
            $included = isset($arguments["IncludedConstant"]) ? $arguments["IncludedConstant"] : "";
            if (!isset($arguments["Include"]) || !strcmp($include = $arguments["Include"], "")) {
                return isset($arguments["Include"]) ? "it was not specified a valid database include file" : "it was not specified a valid DBMS driver type";
            }
            $sub_included = isset($arguments["SubIncludedConstant"]) ? $arguments["SubIncludedConstant"] : "";
            if (!isset($arguments["SubInclude"]) || !strcmp($sub_include = $arguments["SubInclude"], "")) {
                return isset($arguments["SubInclude"]) ? "it was not specified a valid database sub-include file" : "it was not specified a valid DBMS sub-driver type";
            }
            if (!isset($arguments["ClassName"]) || !strcmp($class_name = $arguments["ClassName"], "")) {
                return "it was not specified a valid database class name";
            }
            break;
        default:
            return "\"{$type}\" is not a supported driver type";
    }
    $include_path = isset($arguments["IncludePath"]) ? $arguments["IncludePath"] : "";
    $length = strlen($include_path);
    $directory_separator = defined("DIRECTORY_SEPARATOR") ? DIRECTORY_SEPARATOR : "/";
    $separator = "";
    if ($length) {
        if ($include_path[$length - 1] != $directory_separator) {
            $separator = $directory_separator;
        }
    }
    if (strlen($included) && !defined($included)) {
        $error = MetabaseLoadClass($include, $include_path, "DBMS driver");
        if (strlen($error)) {
            return $error;
        }
    }
    if (strlen($sub_included) && !defined($sub_included)) {
        $error = MetabaseLoadClass($sub_include, $include_path, "DBMS sub driver");
        if (strlen($error)) {
            return $error;
        }
    }
    $db = new $class_name();
    $db->include_path = $include_path;
    if (isset($arguments["Host"])) {
        $db->host = $arguments["Host"];
    }
    if (isset($arguments["User"])) {
        $db->user = $arguments["User"];
    }
    if (isset($arguments["Password"])) {
        $db->password = $arguments["Password"];
    }
    if (isset($arguments["Persistent"])) {
        $db->persistent = $arguments["Persistent"];
    }
    if (isset($arguments["Debug"])) {
        $db->debug = $arguments["Debug"];
    }
    $db->decimal_places = isset($arguments["DecimalPlaces"]) ? $arguments["DecimalPlaces"] : 2;
    $db->lob_buffer_length = isset($arguments["LOBBufferLength"]) ? $arguments["LOBBufferLength"] : 8000;
    if (isset($arguments["LogLineBreak"])) {
        $db->log_line_break = $arguments["LogLineBreak"];
    }
    if (isset($arguments["Options"])) {
        $db->options = $arguments["Options"];
    }
    if (strlen($error = $db->Setup())) {
        return $error;
    }
    if (isset($arguments["Database"])) {
        $db->SetDatabase($arguments["Database"]);
    }
    return "";
}