Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Technical Articles » Building a Windows CE Application with Lazarus and ElevateDB |
CREATE TABLE "Lists" ( "Name" VARCHAR(60) COLLATE "UNI_CI" NOT NULL, "TotalCompleted" INTEGER DEFAULT 0 NOT NULL, "Total" DECIMAL(20,2) DEFAULT 0.00 NOT NULL ) DESCRIPTION 'Contains the basic shopping list information' CREATE TABLE "ListItems" ( "ListName" VARCHAR(60) COLLATE "UNI_CI" NOT NULL, "ItemName" VARCHAR(40) COLLATE "UNI_CI" NOT NULL, "PreferredBrand" VARCHAR(30) COLLATE "UNI_CI", "AreaName" VARCHAR(30) COLLATE "UNI_CI" NOT NULL, "ShoppingOrder" INTEGER DEFAULT 0 NOT NULL, "Quantity" DECIMAL(20,2) DEFAULT 0 NOT NULL, "UnitPrice" DECIMAL(20,2) DEFAULT 0.00 NOT NULL, "ExtendedPrice" DECIMAL(20,2) COMPUTED ALWAYS AS Quantity*UnitPrice, "Completed" BOOLEAN DEFAULT False NOT NULL ) DESCRIPTION 'Contains the actual items on a shopping list' CREATE INDEX "ShoppingOrder" ON "ListItems" ("ListName" COLLATE "UNI_CI", "ShoppingOrder") DESCRIPTION 'Used to shop for a list by area ordering'; CREATE TABLE "Areas" ( "Name" VARCHAR(30) COLLATE "UNI_CI" NOT NULL, "Description" CLOB COLLATE "UNI_CI", "ShoppingOrder" INTEGER DEFAULT 0 NOT NULL ) DESCRIPTION 'Contains all areas used for grouping list items together' CREATE TABLE "Settings" ( "ListName" VARCHAR(60) COLLATE "UNI_CI" ) DESCRIPTION 'Contains the current list name' ALTER TABLE "Lists" ADD CONSTRAINT "Name" PRIMARY KEY ("Name"); ALTER TABLE "ListItems" ADD CONSTRAINT "ListName_ItemName" PRIMARY KEY ("ListName", "ItemName"); ALTER TABLE "Areas" ADD CONSTRAINT "Name" PRIMARY KEY ("Name"), ADD CONSTRAINT "ShoppingOrder" UNIQUE ("ShoppingOrder"); ALTER TABLE "ListItems" ADD CONSTRAINT "ListName" FOREIGN KEY ("ListName") REFERENCES "Lists" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "AreaName" FOREIGN KEY ("AreaName") REFERENCES "Areas" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE "Settings" ADD CONSTRAINT "ListName" FOREIGN KEY ("ListName") REFERENCES "Lists" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION;
{ TShoppingDataModule } procedure TShoppingDataModule.DataModuleCreate(Sender: TObject); begin { Activate the engine. The engine can also be referenced by the generic Engine variable in the edbcomps unit } ShoppingEngine.Active:=True; { Now connect the session } ShoppingSession.Connected:=True; { Check to see if the database exists or whether it needs to be created } with ConfigurationQuery do begin SQL.Text:='SELECT * FROM Databases WHERE Name='+ Engine.QuotedSQLStr('Shopping'); Open; if (RecordCount=0) then begin { Database doesn't exist and we need to create it } Close; SQL.Text:='CREATE DATABASE "Shopping" PATH '+ Engine.QuotedSQLStr(ExtractFilePath(Application.ExeName)+'data'); ExecSQL; end else Close; end; { Now we can open the Shopping database and start to check the metadata for the database. If anything is missing, we create it now in the proper order so as to respect any foreign key <--> primary key RI relationships. NOTE the use of doubled-up single quotes when embedding string constants in the SQL. } with CatalogQuery do begin SQL.Text:='SELECT * FROM Information.Tables WHERE Name=''Areas'''; Open; if (RecordCount=0) then begin Close; SQL.Clear; SQL.Add('CREATE TABLE "Areas"'); SQL.Add('('); SQL.Add('"Name" VARCHAR(30) COLLATE "UNI_CI" NOT NULL,'); SQL.Add('"Description" CLOB COLLATE "UNI_CI",'); SQL.Add('"ShoppingOrder" INTEGER DEFAULT 0 NOT NULL,'); SQL.Add('CONSTRAINT "Name" PRIMARY KEY ("Name"),'); SQL.Add('CONSTRAINT "ShoppingOrder" UNIQUE ("ShoppingOrder")'); SQL.Add(')'); SQL.Add('DESCRIPTION ''Contains all areas used for '+ 'grouping list items together'''); ExecSQL; end else Close;
This web page was last updated on Wednesday, January 13, 2021 at 12:15 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |