Exemple #1
0
function sti_mssql_get_data($connection_string, $data_source_name, $query)
{
    $link = sti_mssql_connect($connection_string);
    $result = sti_mssql_query($query, $link);
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    $columns = array();
    if (function_exists("mssql_fetch_field")) {
        while ($column = mssql_fetch_field($result)) {
            array_push($columns, $column);
        }
    } else {
        foreach (sqlsrv_field_metadata($result) as $field_metadata) {
            array_push($columns, $field_metadata);
        }
    }
    if (function_exists("mssql_fetch_assoc")) {
        while ($row = mssql_fetch_assoc($result)) {
            $xml_output .= "<{$data_source_name}>";
            foreach ($columns as $column) {
                $value = $row[$column->name];
                $column_type = sti_mssql_get_column_type($column->type);
                if ($column_type == "base64Binary") {
                    $value = base64_encode($value);
                } else {
                    if (ord($value[0]) == 0) {
                        $value = sti_bytes_to_int($value);
                    } else {
                        $value = str_replace("&", "&amp;", $value);
                        $value = str_replace("<", "&lt;", $value);
                        $value = str_replace(">", "&gt;", $value);
                    }
                }
                $columnName = encodeName($column->name);
                $xml_output .= "<{$columnName}>{$value}</{$columnName}>";
            }
            $xml_output .= "</{$data_source_name}>";
        }
    } else {
        while ($row = sqlsrv_fetch_array($result)) {
            $xml_output .= "<{$data_source_name}>";
            foreach ($columns as $column) {
                $value = $row[$column["Name"]];
                $column_type = sti_mssql_get_column_type($field_metadata["Type"]);
                if ($column_type == "base64Binary") {
                    $value = base64_encode($value);
                } else {
                    if (ord($value[0]) == 0) {
                        $value = sti_bytes_to_int($value);
                    } else {
                        $value = str_replace("&", "&amp;", $value);
                        $value = str_replace("<", "&lt;", $value);
                        $value = str_replace(">", "&gt;", $value);
                    }
                }
                $columnName = encodeName($column["Name"]);
                $xml_output .= "<{$columnName}>{$value}</{$columnName}>";
            }
            $xml_output .= "</{$data_source_name}>";
        }
    }
    $xml_output .= "</Database>";
    mssql_free_result($result);
    mssql_close($link);
    return $xml_output;
}
Exemple #2
0
                    pieError("FormatError", array('file' => $file));
                }
                $history[$meta['stamp']] = $meta;
                $meta = array();
            } elseif (preg_match('/^(\\w+)=(.+)$/', $line, $match)) {
                $meta[$match[1]] = trim($match[2]);
            } else {
                pieError("FormatError", array('file' => $file));
            }
        }
        fclose($f);
        ksort($history);
        foreach ($history as $stamp => $meta) {
            $path = $_REQUEST['filepath'] . "/" . encodeName("{$name} {$stamp}");
            if (!file_exists($path)) {
                $path = $_REQUEST['filepath'] . "/" . encodeName($name);
                if (!file_exists($path)) {
                    pieError("FileNotFound", array('file' => htmlspecialchars($file), 'stamp' => $stamp));
                }
            }
            if (!importFile($path, $meta)) {
                pieError("ImportError", array('file' => htmlspecialchars($file)));
            }
            $count++;
            $size += filesize($path);
        }
    }
} else {
    // Retrieve the list of files of the FILE path.
    if (!($list = getFileList($_REQUEST['filepath']))) {
        pieError("ImportError");