Skip to content
Permalink
Browse files

documentation fixes from #232

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Sep 4, 2019
1 parent 652656c commit 458c06efddf4cd4956aba7eec8147ccb10083386
Showing with 57 additions and 57 deletions.
  1. +2 −2 SQLite3/Documentation/Synopse SQLite3 Framework.pro
  2. +36 −36 SQLite3/mORMot.pas
  3. +1 −1 SQLite3/mORMoti18n.pas
  4. +14 −14 SynCommons.pas
  5. +1 −1 SynLZO.pas
  6. +2 −2 SynSQLite3.pas
  7. +1 −1 SynopseCommit.inc
@@ -2356,7 +2356,7 @@ You can optionally specify the associated table, using a custom {\f1\fs20 TID} t
! property OrderedByCascade: TSQLRecordClientToBeDeletedID
! read fOrderedByCascade write fOrderedByCascade;
! ...
Those three published fields will be able to store a {\f1\fs20 Int64} foreign key, and the ORM will ensure a corresponding {\i index} is created on the database, to speedup search on their values.\line But their type - {\f1\fs20 TID}, {\f1\fs20 TSQLRecordClientID}, or TSQLRecordClientToBeDeletedID - will define how the deletion process will be processed.
Those three published fields will be able to store a {\f1\fs20 Int64} foreign key, and the ORM will ensure a corresponding {\i index} is created on the database, to speedup search on their values.\line But their type - {\f1\fs20 TID}, {\f1\fs20 TSQLRecordClientID}, or {\f1\fs20 TSQLRecordClientToBeDeletedID} - will define how the deletion process will be processed.
By using the generic {\f1\fs20 TID} type, the first {\f1\fs20 Client} property won't have any reference to any table, so no deletion tracking will take place.
On the other hand, {\i following the type naming convention}, the others {\f1\fs20 OrderedBy} and {\f1\fs20 OrderedByCascade} properties will be associated with the {\f1\fs20 TSQLRecordClient} table of the data model.\line In fact, the ORM will retrieve the {\f1\fs20 'TSQLRecordClientID'} or {\f1\fs20 'TSQLRecordClientToBeDeletedID'} type names, and search for a {\f1\fs20 TSQLRecord} associated by trimming {\f1\fs20 *[ToBeDeleted]ID}, which is {\f1\fs20 TSQLRecordClient} in this case.\line As a result, the ORM will be able to track any {\f1\fs20 TSQLRecordClient} deletion: for any row pointing to the deleted record, it will ensure that this {\f1\fs20 OrderedBy} property will be reset to 0, or that the row containing the {\f1\fs20 OrderedByCascade} property will be deleted. Note that the framework won't define a {\f1\fs20 ON DELETE SET DEFAULT} or {\f1\fs20 ON DELETE CASCADE} foreign key via SQL, but emulate them {\i at ORM level}.
:148 TRecordReference and TRecordReferenceToBeDeleted
# console.error("Error with the twitterverse:", error);
# }
# );
Taken from @http://domenic.me/2012/10/14/youre-missing-the-point-of-promises
Taken from @https://blog.domenic.me/youre-missing-the-point-of-promises/
This kind of code will be perfectly readable for a {\i JavaScript} daily user, or someone fluent with functional languages.
But the following blocking/synchronous code may sound much more familiar, safer and less verbose, to most {\i Delphi} / Java / C# programmer:
#try {
@@ -8118,6 +8118,12 @@ TSQLRecord = class(TObject)
procedure FillValue(PropName, Value: PUTF8Char; wasString: boolean;
FieldBits: PSQLFieldBits=nil);

/// return true if all published properties values in Other are identical to
// the published properties of this object
// - instances must be of the same class type
// - only simple fields (i.e. not TSQLRawBlob/TSQLRecordMany) are compared
// - comparison is much faster than SameValues() below
function SameRecord(Reference: TSQLRecord): boolean;
/// return true if all published properties values in Other are identical to
// the published properties of this object
// - work with different classes: Reference properties name must just be
@@ -8126,12 +8132,6 @@ TSQLRecord = class(TObject)
// - compare the text representation of the values: fields may be of different
// type, encoding or precision, but still have same values
function SameValues(Reference: TSQLRecord): boolean;
/// return true if all published properties values in Other are identical to
// the published properties of this object
// - instances must be of the same class type
// - only simple fields (i.e. not TSQLRawBlob/TSQLRecordMany) are compared
// - comparaison is much faster than SameValues() above
function SameRecord(Reference: TSQLRecord): boolean;
/// clear the values of all published properties, and also the ID property
procedure ClearProperties; overload;
/// clear the values of specified published properties
// - you can specify a Row index to be updated during the sort in PCurrentRow
// - sort is very fast, even for huge tables (more faster than any indexed
// SQL query): 500,000 rows are sorted instantly
// - this optimized sort implementation does the comparaison first by the
// - this optimized sort implementation does the comparison first by the
// designed field, and, if the field value is identical, the ID value is
// used (it will therefore sort by time all identical values)
procedure SortFields(Field: integer; Asc: boolean=true;
// (X'53514C697465' e.g.)
// - since TSQLTable data is PUTF8Char, string type is sftUTF8Text only
function FieldType(Field: integer; out FieldTypeInfo: PSQLTableFieldType): TSQLFieldType; overload;
/// get the appropriate Sort comparaison function for a field,
/// get the appropriate Sort comparison function for a field,
// nil if not available (bad field index or field is blob)
// - field type is guessed from first data row
function SortCompare(Field: integer): TUTF8Compare;
// ! Model.VirtualTableRegister(TSQLRecordDali1,TSQLVirtualTableJSON);
TSQLRecordVirtualTableAutoID = class(TSQLRecordVirtual);

/// special comparaison function for sorting ftRecord (TRecordReference/RecordRef)
/// special comparison function for sorting ftRecord (TRecordReference/RecordRef)
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareRecord(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftBoolean
/// special comparison function for sorting sftBoolean
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareBoolean(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftEnumerate, sftSet or sftID
/// special comparison function for sorting sftEnumerate, sftSet or sftID
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareUInt32(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftInteger, sftTID, sftRecordVersion
/// special comparison function for sorting sftInteger, sftTID, sftRecordVersion
// sftTimeLog/sftModTime/sftCreateTime or sftUnixTime/sftUnixMSTime UTF-8 encoded
// values in the SQLite3 database or JSON content
function UTF8CompareInt64(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftCurrency
/// special comparison function for sorting sftCurrency
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareCurr64(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftFloat
/// special comparison function for sorting sftFloat
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareDouble(P1,P2: PUTF8Char): PtrInt;

/// special comparaison function for sorting sftDateTime or sftDateTimeMS
/// special comparison function for sorting sftDateTime or sftDateTimeMS
// UTF-8 encoded values in the SQLite3 database or JSON content
function UTF8CompareISO8601(P1,P2: PUTF8Char): PtrInt;


type
/// a static object is used for smaller recursive stack size and faster code
// - these special sort implementation do the comparaison first by the
// - these special sort implementation do the comparison first by the
// designed field, and, if the field value is identical, the ID value is
// used (it will therefore sort by time all identical values)
// - code generated is very optimized: stack and memory usage, CPU registers
SetPP(@Results[P*Params.FieldCount+Params.FieldIndex],P);
repeat
// this loop has no multiplication -> most of the time is spent in compIJ
if Params.Asc then begin // ascending order comparaison
if Params.Asc then begin // ascending order comparison
while compI<0 do begin
inc(I);
inc(PByte(CI),FieldCountNextPtr); // next row
dec(J);
dec(PByte(CJ),FieldCountNextPtr); // previous row
end;
end else begin // descending order comparaison
end else begin // descending order comparison
while compI>0 do begin
inc(I);
inc(PByte(CI),FieldCountNextPtr); // next row
end;
end;

function TSQLRecord.SameRecord(Reference: TSQLRecord): boolean;
var i: integer;
begin
result := false;
if (self=nil) or (Reference=nil) or
(PSQLRecordClass(Reference)^<>PSQLRecordClass(Self)^) or (Reference.fID<>fID) then
exit;
with RecordProps do
for i := 0 to high(SimpleFields) do
// compare not TSQLRawBlob/TSQLRecordMany fields
with SimpleFields[i] do
if CompareValue(self,Reference,false)<>0 then
exit; // properties don't have the same value
result := true;
end;

function TSQLRecord.SameValues(Reference: TSQLRecord): boolean;
var O: TSQLPropInfo;
i: integer;
if CompareValue(self,Reference,false)<>0 then
exit; // properties don't have the same value
end else begin
// comparaison of all properties of Reference against self
// comparison of all properties of Reference against self
This := RecordProps;
Ref := Reference.RecordProps;
for i := 0 to high(Ref.SimpleFields) do
result := true;
end;

function TSQLRecord.SameRecord(Reference: TSQLRecord): boolean;
var i: integer;
begin
result := false;
if (self=nil) or (Reference=nil) or
(PSQLRecordClass(Reference)^<>PSQLRecordClass(Self)^) or (Reference.fID<>fID) then
exit;
with RecordProps do
for i := 0 to high(SimpleFields) do
// compare not TSQLRawBlob/TSQLRecordMany fields
with SimpleFields[i] do
if CompareValue(self,Reference,false)<>0 then
exit; // properties don't have the same value
result := true;
end;

procedure TSQLRecord.ClearProperties;
var i: integer;
begin
inherited Create;
Server := aServer;
Call := @aCall;
Method := StringToMethod(aCall.method);;
Method := ToMethod(aCall.Method);;
fThreadServer := @ServiceContext;
fThreadServer^.Request := self;
end;
@@ -1315,7 +1315,7 @@ procedure SetCurrentLanguage(aLanguage: TLanguages; aForceEnglishIfNoMsgFile: bo
(LanguageCharSet[LCIDToLanguage(GetUserDefaultLCID)]=CharSet) then begin
// NormToUpper/Lower[] was filled with LOCALE_USER_DEFAULT values
// -> OK if same CHARSET, and not multi-byte
i18nCompareStr := // not MBCS strict comparaison is always valid
i18nCompareStr := // not MBCS strict comparison is always valid
{$ifdef ENHANCEDRTL}CompareStr{$else}i18nInnerCompareStr{$endif};
// CompareText in SysUtils.pas uses NormToUpper[], this uses i18nToUpper[]:
i18nCompareText := i18nInnerCompareText;
@@ -1377,7 +1377,7 @@ function ToUTF8({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} guid: TGUI
{$ifndef NOVARIANTS}

type
/// function prototype used internally for variant comparaison
/// function prototype used internally for variant comparison
// - used in mORMot.pas unit e.g. by TDocVariantData.SortByValue
TVariantCompare = function(const V1,V2: variant): PtrInt;

@@ -1772,7 +1772,7 @@ function VarRecAsChar(const V: TVarRec): integer;
{$ifdef HASINLINE}inline;{$endif}

type
/// function prototype used internally for UTF-8 buffer comparaison
/// function prototype used internally for UTF-8 buffer comparison
// - used in mORMot.pas unit during TSQLTable rows sort and by TSQLQuery
TUTF8Compare = function(P1,P2: PUTF8Char): PtrInt;

@@ -2814,7 +2814,7 @@ function UpperCopyShort(dest: PAnsiChar; const source: shortstring): PAnsiChar;

{$ifdef USENORMTOUPPER}

/// fast UTF-8 comparaison using the NormToUpper[] array for all 8 bits values
/// fast UTF-8 comparison using the NormToUpper[] array for all 8 bits values
// - this version expects u1 and u2 to be zero-terminated
// - this version will decode each UTF-8 glyph before using NormToUpper[]
// - current implementation handles UTF-16 surrogates
@@ -2834,15 +2834,15 @@ function UTF8UpperCopy(Dest, Source: PUTF8Char; SourceChars: Cardinal): PUTF8Cha
function UTF8UpperCopy255(dest: PAnsiChar; const source: RawUTF8): PUTF8Char;
{$ifdef HASINLINE}inline;{$endif}

/// fast UTF-8 comparaison using the NormToUpper[] array for all 8 bits values
/// fast UTF-8 comparison using the NormToUpper[] array for all 8 bits values
// - this version expects u1 and u2 not to be necessary zero-terminated, but
// uses L1 and L2 as length for u1 and u2 respectively
// - use this function for SQLite3 collation (TSQLCollateFunc)
// - this version will decode the UTF-8 content before using NormToUpper[]
// - current implementation handles UTF-16 surrogates
function UTF8ILComp(u1, u2: PUTF8Char; L1,L2: cardinal): PtrInt;

/// fast case-insensitive Unicode comparaison
/// fast case-insensitive Unicode comparison
// - use the NormToUpperAnsi7Byte[] array, i.e. compare 'a'..'z' as 'A'..'Z'
// - this version expects u1 and u2 to be zero-terminated
function AnsiICompW(u1, u2: PWideChar): PtrInt;
@@ -2944,7 +2944,7 @@ function TrimLeft(const S: RawUTF8): RawUTF8;
// newline, space, and tab characters
function TrimRight(const S: RawUTF8): RawUTF8;

/// fast WinAnsi comparaison using the NormToUpper[] array for all 8 bits values
/// fast WinAnsi comparison using the NormToUpper[] array for all 8 bits values
function AnsiIComp(Str1, Str2: PWinAnsiChar): PtrInt;
{$ifndef USENORMTOUPPER} {$ifdef PUREPASCAL}
{$ifdef HASINLINE}inline;{$endif} {$endif} {$endif}
// - this version is not optimized for speed, but for correctness
function crc16(Data: PAnsiChar; Len: integer): cardinal;

// our custom hash/checksum function, specialized for Text comparaison
// our custom hash/checksum function, specialized for Text comparison
// - it is a checksum algorithm, not a hash function: has less colision than
// Adler32 for short strings, but more than xxhash32 or crc32/crc32c
// - written in simple plain pascal, with no L1 CPU cache pollution
// $ hash32 9.7KB in 487us i.e. 1,026,694/s, aver. 0us, 9.5 GB/s
function Hash32(Data: PCardinalArray; Len: integer): cardinal; overload;

// our custom hash/checsum function, specialized for Text comparaison
// our custom hash/checsum function, specialized for Text comparison
// - it is a checksum algorithm, not a hash function: has less colision than
// Adler32 for short strings, but more than xxhash32 or crc32/crc32c
// - is faster than CRC32 or Adler32, since uses DQWord (128-bit) aligned read

/// convert a Iso8601 encoded string into a TTimeLog value
// - handle TTimeLog bit-encoded Int64 format
// - use this function only for fast comparaison between two Iso8601 date/time
// - use this function only for fast comparison between two Iso8601 date/time
// - conversion is faster than Iso8601ToDateTime: use only binary integer math
// - ContainsNoTime optional pointer can be set to a boolean, which will be
// set according to the layout in P (e.g. TRUE for '2012-05-26')

/// convert a Iso8601 encoded string into a TTimeLog value
// - handle TTimeLog bit-encoded Int64 format
// - use this function only for fast comparaison between two Iso8601 date/time
// - use this function only for fast comparison between two Iso8601 date/time
// - conversion is faster than Iso8601ToDateTime: use only binary integer math
function Iso8601ToTimeLog(const S: RawByteString): TTimeLog;
{$ifdef PUREPASCAL} {$ifdef HASINLINE}inline;{$endif} {$endif}

function Pos(const substr, str: RawUTF8): Integer; overload;
begin
Result := PosEx(substr, str, 1);
Result := PosEx(substr,str,1);
end;

function IntToString(Value: integer): string;
end;
{$else}
function AnsiIComp(Str1, Str2: PWinAnsiChar): PtrInt;
asm // fast 8 bits WinAnsi comparaison using the NormToUpper[] array
asm // fast 8 bits WinAnsi comparison using the NormToUpper[] array
cmp eax, edx
je @2
test eax, edx // is either of the strings perhaps nil?
function UTF8IComp(u1, u2: PUTF8Char): PtrInt;
var c2: PtrInt;
table: {$ifdef CPUX86NOTPIC}TNormTableByte absolute NormToUpperByte{$else}PNormTableByte{$endif};
begin // fast UTF-8 comparaison using the NormToUpper[] array for all 8 bits values
begin // fast UTF-8 comparison using the NormToUpper[] array for all 8 bits values
{$ifndef CPUX86NOTPIC}table := @NormToUpperByte;{$endif}
if u1<>u2 then
if u1<>nil then
extra,i: integer;
table: {$ifdef CPUX86NOTPIC}TNormTableByte absolute NormToUpperByte{$else}PNormTableByte{$endif};
label neg,pos;
begin // fast UTF-8 comparaison using the NormToUpper[] array for all 8 bits values
begin // fast UTF-8 comparison using the NormToUpper[] array for all 8 bits values
{$ifndef CPUX86NOTPIC}table := @NormToUpperByte;{$endif}
if u1<>u2 then
if (u1<>nil) and (L1<>0) then
@@ -52,7 +52,7 @@
written in optimized pascal code for Delphi 3 up to Delphi 2009
with a tuned asm version available
* offers *extremely* fast compression and decompression
with good compression rate, in comparaison with its speed
with good compression rate, in comparison with its speed
* original LZO written in ANSI C - pascal+asm conversion by A.Bouchez
* simple but very fast direct file compression:
SynLZO compressed files read/write is faster than copying plain files!
@@ -525,8 +525,8 @@ interface
// TObject(p).Free
TSQLDestroyPtr = procedure(p: pointer); cdecl;

/// SQLite3 collation (i.e. sort and comparaison) function prototype
// - this function MUST use s1Len and s2Len parameters during the comparaison:
/// SQLite3 collation (i.e. sort and comparison) function prototype
// - this function MUST use s1Len and s2Len parameters during the comparison:
// s1 and s2 are not zero-terminated
// - used by sqlite3.create_collation low-level function
TSQLCollateFunc = function(CollateParam: pointer; s1Len: integer; s1: pointer;
@@ -1 +1 @@
'1.18.5327'
'1.18.5328'

0 comments on commit 458c06e

Please sign in to comment.
You can’t perform that action at this time.