From feadf973f2a0b7a50cbd76d40d1bb1a74a5ead34 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Tue, 22 Oct 2024 22:39:55 +0200 Subject: [PATCH] Updated MSSQL Script for active_record_showcase demo --- .../FDConnectionConfigU.pas | 6 ++-- samples/activerecord_showcase/MainFormU.pas | 7 ++-- .../activerecorddb_mssqlserver_script.sql | 36 +++++++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/samples/activerecord_showcase/FDConnectionConfigU.pas b/samples/activerecord_showcase/FDConnectionConfigU.pas index 1df46249..615f8fb6 100644 --- a/samples/activerecord_showcase/FDConnectionConfigU.pas +++ b/samples/activerecord_showcase/FDConnectionConfigU.pas @@ -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'); diff --git a/samples/activerecord_showcase/MainFormU.pas b/samples/activerecord_showcase/MainFormU.pas index 5926003b..a4c1e5b2 100644 --- a/samples/activerecord_showcase/MainFormU.pas +++ b/samples/activerecord_showcase/MainFormU.pas @@ -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(lID); try diff --git a/samples/data/activerecorddb_mssqlserver_script.sql b/samples/data/activerecorddb_mssqlserver_script.sql index 8f8576f5..805e4fdf 100644 --- a/samples/data/activerecorddb_mssqlserver_script.sql +++ b/samples/data/activerecorddb_mssqlserver_script.sql @@ -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, - NOTE nvarchar(max), + 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,