Updated MSSQL Script for active_record_showcase demo

This commit is contained in:
Daniele Teti 2024-10-22 22:39:55 +02:00
parent 913b9cb3c2
commit feadf973f2
3 changed files with 43 additions and 6 deletions

View File

@ -78,8 +78,10 @@ begin
LParams := TStringList.Create;
try
LParams.Add('Database=activerecorddb');
LParams.Add('OSAuthent=Yes');
LParams.Add('Server=DANIELETETI\SQLEXPRESS');
LParams.Add('OSAuthent=No');
LParams.Add('Server=localhost');
LParams.Add('User_Name=sa');
LParams.Add('Password=Daniele123!');
if AIsPooled then
begin
LParams.Add('Pooled=True');

View File

@ -2226,8 +2226,7 @@ begin
lCust.Note := 'Μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην 😁';
lCust.Insert;
lID := lCust.ID;
Log('Just inserted CustomerWithVersion ' + lID.ValueOrDefault.ToString);
lCust.Store;
Log('Just inserted CustomerWithVersion with ID = ' + lID.ValueOrDefault.ToString + ' and version = ' + lCust.ObjVersion.ToString);
finally
lCust.Free;
end;
@ -2236,10 +2235,14 @@ begin
try
lCust.CompanyName := 'Alphabet Inc.';
lCust.Store;
Log('Just updated CustomerWithVersion with ID = ' + lID.ValueOrDefault.ToString + ' and version = ' + lCust.ObjVersion.ToString);
finally
lCust.Free;
end;
ShowMessage('Now we are going to create a logical conflict - an exception will be raised and no data will be lost');
// Let's load 2 instances
var lCust1 := TMVCActiveRecord.GetByPK<TCustomerWithVersion>(lID);
try

View File

@ -6,15 +6,27 @@ CREATE TABLE articles (
);
CREATE TABLE customers (
id integer IDENTITY(1, 1) ,
id integer IDENTITY(1, 1) ,
code nvarchar(20),
description nvarchar(200),
city nvarchar(200),
rating INTEGER,
last_contact_timestamp datetime NULL,
NOTE nvarchar(max),
CONSTRAINT customers_pk PRIMARY KEY (id)
);
CREATE TABLE customers2 (
id bigint IDENTITY(1, 1) ,
code nvarchar(20),
description nvarchar(200),
city nvarchar(200),
NOTE nvarchar(max),
rating integer,
last_contact_timestamp datetime NULL,
);
CREATE TABLE customers_plain (
id integer NOT NULL,
code nvarchar(20),
@ -35,6 +47,26 @@ CREATE TABLE customers_with_code (
rating smallint
);
CREATE TABLE customers_with_guid (
idguid UNIQUEIDENTIFIER NOT NULL,
code varchar(20) NULL,
description varchar(200) NULL,
city varchar(200) NULL,
note text NULL,
rating smallint NULL,
CONSTRAINT customers_with_guid_pk PRIMARY KEY (idguid)
);
CREATE TABLE customers_with_version (
id bigint IDENTITY(1, 1),
code varchar(20),
description varchar(200),
city varchar(200),
note text,
rating integer,
objversion integer
);
CREATE TABLE order_details (
id integer IDENTITY(1, 1) ,
id_order integer NOT NULL,