Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
Delphi 10.2 Tokyo Professional
|
Re: Php: Datenbank-Backup...
24. Okt 2005, 16:52
[Unten folgt ein //NACHTRAG]
Ich denke, es würde gehen. Diese Funktion hier ist aber allgemeiner:
Code:
function SplitSqlStatements(&$fulltext)
{
$states = array(
// Normal (top-level)
0 => array(
"#" => array( 's' => 1, 'a' => 0 ),
"-" => array( 's' => 2, 'a' => 0 ),
"/" => array( 's' => 4, 'a' => 0 ),
"\n" => array( 's' => 0, 'a' => 1 ),
"'" => array( 's' => 7, 'a' => 1 ),
'"' => array( 's' => 9, 'a' => 1 ),
'`' => array( 's' => 11, 'a' => 1 ),
';' => array( 's' => -1, 'a' => 0 ),
999 => array( 's' => 0, 'a' => 1 ),
),
// Kommentar bis Zeilenende
1 => array(
"\n" => array( 's' => 0, 'a' => 0 ),
999 => array( 's' => 1, 'a' => 0 ),
),
// Minuszeichen gesehen
2 => array(
"-" => array( 's' => 3, 'a' => 0 ),
999 => array( 's' => 0, 'a' => 1, 'i' => "-" ),
),
// Zweites Minuszeichen gesehen
3 => array(
" " => array( 's' => 1, 'a' => 0 ),
999 => array( 's' => 0, 'a' => 2, 'i' => "--" ),
),
// Schrägstrich gesehen
4 => array(
"*" => array( 's' => 5, 'a' => 0 ),
999 => array( 's' => 0, 'a' => 2, 'i' => "/" ),
),
// C-style Kommentar
5 => array(
"*" => array( 's' => 6, 'a' => 0 ),
999 => array( 's' => 5, 'a' => 0 ),
),
// Stern gesehen im C-style Kommentar
6 => array(
"/" => array( 's' => 0, 'a' => 0 ),
999 => array( 's' => 5, 'a' => 0 ),
),
// Single quote
7 => array(
"'" => array( 's' => 0, 'a' => 1 ),
"\\" => array( 's' => 8, 'a' => 1 ),
999 => array( 's' => 7, 'a' => 1 ),
),
// Backslash im single quote
8 => array(
999 => array( 's' => 7, 'a' => 1 ),
),
// Double quote
9 => array(
'"' => array( 's' => 0, 'a' => 1 ),
"\\" => array( 's' => 10, 'a' => 1 ),
999 => array( 's' => 9, 'a' => 1 ),
),
// Backslash im single quote
10 => array(
999 => array( 's' => 9, 'a' => 1 ),
),
// Double quote
11 => array(
'`' => array( 's' => 0, 'a' => 1 ),
"\\" => array( 's' => 12, 'a' => 1 ),
999 => array( 's' => 11, 'a' => 1 ),
),
// Backslash im backquote
12 => array(
999 => array( 's' => 11, 'a' => 1 ),
),
);
$state = 0;
$result = array();
$stmt = "";
$len = strlen($fulltext);
for ($k = 0; $k < $len; $k++)
{
$ch = $fulltext{$k};
$ix = isset($states[$state][$ch]) ? $ch : 999;
if (!empty($states[$state][$ix]['i']))
$stmt .= $states[$state][$ix]['i'];
if (!empty($states[$state][$ix]['a']))
if (!empty($stmt) || ($ch != ' ' && $ch != "\n"))
$stmt .= $ch;
$state = $states[$state][$ix]['s'];
if ($state == -1)
{
if (!empty($stmt))
$result[] = $stmt;
$stmt = "";
$state = 0;
}
}
if (!empty($stmt))
$result[] = $stmt;
return $result;
}
//NACHTRAG:
Hab's die Datei von oben noch mal ein bisschen angepasst und angehängt. Die Klasse ist jetzt um die Methode "Import" erweitert.
|