- Код: Выделить всё
var
newFile : Boolean;
begin
SQLite3Connection1.Close; // Ensure the connection is closed when we start
try
// Since we're making this database for the first time,
// check whether the file already exists
newFile := not FileExists(SQLite3Connection1.DatabaseName);
if newFile then
begin
// Create the database and the tables
try
SQLite3Connection1.Open;
SQLTransaction1.Active := true;
// Here we're setting up a table named "DATA" in the new database
SQLite3Connection1.ExecuteDirect('CREATE TABLE "DATA"('+
' "id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,'+
' "Current_Time" DateTime NOT NULL,'+
' "User_Name" Char(128) NOT NULL,'+
' "Info" Char(128) NOT NULL);');
// Creating an index based upon id in the DATA Table
SQLite3Connection1.ExecuteDirect('CREATE UNIQUE INDEX "Data_id_idx" ON "DATA"( "id" );');
SQLTransaction1.Commit;
ShowMessage('Succesfully created database.');
except
ShowMessage('Unable to Create new Database');
end;
end;
except
ShowMessage('Unable to check if database file exists');
end;
end;
Моё отличие состояло в том, что в функцию SQLite3Connection1.ExecuteDirect() я передавал запрос, в котором было несколько CREATE TABLE(); но по факту, после выполнения запроса,(при просмотре списка таблиц), в базе была только одна таблица(первая из списка CREATE TABLE). Правильно ли я понимаю, что для каждого CREATE TABLE нужно вызывать свой ExecuteDirect("CREATE TABLE(...)")? Если нет, то как правильно делать(киньте примером), ибо в примерах и туториалах этот момент почему-то опущен, везде создаётся БД в одну табличку либо примеры идут уже на созданной
