Registriert seit: 21. Jul 2006
Ort: Hamburg
143 Beiträge
Delphi 12 Athens
|
AW: SQL Semicolon im String -> Fehler bei Insert
26. Mai 2024, 18:10
Die Routine sieht so aus:
Code:
function TfrmBackupRestore.GetSqlVersion: string;
begin
Result := 'Unbekannt';
try
with qryData.SQL do begin
Clear;
Add('SELECT sqlite_version()')
end;
qryData.Open;
Result := qryData.FieldByName('sqlite_version()').AsString;
qryData.CLose;
finally
end;
end;
procedure TfrmBackupRestore.DoBackup;
var
SqlFile: TextFile;
Loop: Integer;
begin
AssignFile(SqlFile, SqlBackupFileName);
Rewrite(SqlFile);
if IOResult = 0 then begin
tblData.Active := True;
tblData.Open;
try
WriteLn(SqlFile, '-- --------------------------------------------------------');
WriteLn(SqlFile, '-- Host: ' + DbName + SqLiteSqlExt);
WriteLn(SqlFile, '-- Server-Version: ' + dmMain.SqlConnection.Drivername + ' Version : ' + GetSqlVersion);
WriteLn(SqlFile, '-- Server - Betriebssystem: ' + TOSVersion.Name);
WriteLn(SqlFile, '-- Generator: ' + FileVersion.strProductName + Space + strVersion + FileVersion.strFileVersion);
WriteLn(SqlFile, '-- --------------------------------------------------------');
WriteLn(SqlFile);
WriteLn(SqlFile, '-- Exportiere Datenbank - Struktur für Mediathek');
WriteLn(SqlFile, '/*!40000 CREATE DATABASE if not EXISTS Mediathek */;');
WriteLn(SqlFile);
WriteLn(SqlFile, '-- Exportiere Struktur von Tabelle Mediathek.Mediathek');
WriteLn(SqlFile, 'CREATE TABLE if not EXISTS Mediathek(ID INTEGER PRIMARY KEY AUTOINCREMENT, Interpret VARCHAR not NULL, Album VARCHAR not NULL, Titel VARCHAR not NULL, FileName VARCHAR not NULL UNIQUE);');
WriteLn(SqlFile);
WriteLn(SqlFile, '-- Exportiere Daten aus Tabelle Mediathek.Mediathek');
WriteLn(SqlFile, 'DELETE FROM Mediathek;');
WriteLn(SqlFile, '/*!40000 ALTER TABLE "Mediathek" DISABLE KEYS */;');
tblData.First;
WriteLn(SqlFile, 'INSERT INTO Mediathek (' + QuotedStr('ID') + ',' + QuotedStr('Interpret') + ',' + QuotedStr('Album') + ',' + QuotedStr('Titel') + ',' + QuotedStr('FileName') + ') VALUES');
Caption := tblData.RecordCount.ToString;
for Loop := 0 to tblData.RecordCount - 2 do begin
WriteLn(SqlFile, '(' + tblDataID.AsString + ',' + QuotedStr(tblDataInterpret.AsWideString) + ',' + QuotedStr(tblDataAlbum.AsWideString) + ',' + QuotedStr(tblDataTitel.AsWideString) + ',' + QuotedStr(tblDataFileName.AsWideString) + '),');
tblData.Next;
Application.ProcessMessages;
end;
tblData.Last;
WriteLn(SqlFile, '(' + tblDataID.AsString + ',' + QuotedStr(tblDataInterpret.AsWideString) + ',' + QuotedStr(tblDataAlbum.AsWideString) + ',' + QuotedStr(tblDataTitel.AsWideString) + ',' + QuotedStr(tblDataFileName.AsWideString) + ');');
WriteLn(SqlFile, '/*!40000 ALTER TABLE "Mediathek" ENABLE KEYS */;');
WriteLn(SqlFile);
WriteLn(SqlFile, '-- Exportiere Struktur von Tabelle Mediathek.TempData');
WriteLn(SqlFile, 'CREATE TABLE IF NOT EXISTS TempData (ID INTEGER PRIMARY KEY AUTOINCREMENT, OrgId INT NOT NULL UNIQUE, FileName VARCHAR NOT NULL UNIQUE);');
WriteLn(SqlFile);
WriteLn(SqlFile, '-- Exportiere Daten aus Tabelle Mediathek.TempData');
WriteLn(SqlFile, 'DELETE FROM TempData;');
WriteLn(SqlFile, '/*!40000 ALTER TABLE "TempData" DISABLE KEYS */;');
WriteLn(SqlFile, '/*!40000 ALTER TABLE "TempData" ENABLE KEYS */;');
finally
CloseFile(SqlFile);
end;
tblData.Close;
tblData.Active := False;
end else begin
ErrorDialog('Die Sicherungsdatei: ' + SqlBackupFileName + CRLF + 'konnte nicht angelegt werden !');
end;
end;
Debuggers don’t remove bugs, they only show them in slow-motion.
|