Permalink
Browse files

new TSQLTable.FieldAsString() overloaded methods

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Jan 31, 2019
1 parent 6d27be5 commit e18422eecf6dc0199f4b9e4557ab68ce6db9fabb
Showing with 83 additions and 14 deletions.
  1. +1 −1 CrossPlatform/SynCrossPlatformREST.pas
  2. +75 −8 SQLite3/mORMot.pas
  3. +2 −2 SynBigTable.pas
  4. +2 −0 SynCommons.pas
  5. +1 −1 SynCrtSock.pas
  6. +1 −1 SynSM.pas
  7. +1 −1 SynopseCommit.inc
@@ -566,7 +566,7 @@ TSQLRestClientURI = class;
// so e.g. for a sicShared instance, you can safely write:
// ! aIntegerResult := TServiceCalculator.Create(aClient).Add(10,20);
// - as you already noted, server-side interface-based services are in fact
// consummed without any interface in this cross-platform unit!
// consumed without any interface in this cross-platform unit!
TServiceClientAbstract = class{$ifndef ISDWS}(TInterfacedObject){$endif}
protected
fClient: TSQLRestClientURI;
@@ -475,7 +475,7 @@
- new TSQLRestServer.SessionGetUser method to be used e.g. by any
TSQLRestServerCallBack method implementation to retrieve the connected user
- now the TSQLAuthUser instance retrieved during the session opening will
retrieve the Data BLOB field (ready to be consummed on the server side)
retrieve the Data BLOB field (ready to be consumed on the server side)
- introduced TSQLRestServerSessionContext structure to include current User
and Group ID to the execution context (in addition to the Session ID)
- TSQLRestServerStaticInMemory binary format changed: now will store its
@@ -4203,7 +4203,7 @@ TJSONSerializer = class(TJSONWriter)
/// customize TSQLRecord.GetJSONValues serialization process
// - jwoAsJsonNotAsString will force TSQLRecord.GetJSONValues to serialize
// nested property instances as a JSON object/array, not a JSON string:
// i.e. root/table/id REST will be ready-to-be-consummed from AJAX clients
// i.e. root/table/id REST will be ready-to-be-consumed from AJAX clients
// (e.g. TSQLPropInfoRTTIObject.GetJSONValues as a JSON object, and
// TSQLPropInfoRTTIDynArray.GetJSONValues as a JSON array)
// - jwoID_str will add an "ID_str":"12345" property to the default
@@ -8206,28 +8206,54 @@ TSQLRecord = class(TObject)
TSQLRecordArray = array[0..MaxInt div SizeOf(TSQLRecord)-1] of TSQLRecord;
PSQLRecordArray = ^TSQLRecordArray;

/// root class for defining and mapping database records with NOCASE collation
/// root class for defining and mapping database records with case-insensitive
// NOCASE collation
// - by default, any sftUTF8Text field (RawUTF8, UnicodeString, WideString
// properties) will use our Unicode SYSTEMNOCASE SQLite3 collation, which calls
// UTF8ILComp() to handle most western languages, but is not standard
// - you may inherit from this class to ensure any text field will use the
// faster and SQLite3 built-in NOCASE collation, handling only 7-bit A-Z chars
// - inherit from TSQLRecordNoCase if you expect your text fields to contain
// only basic unaccentued ASCCI characters, and to be opened by any standard
// SQlite3 library or tool (outside of SynSQLite3.pas/SynDBExplorer)
// - inherit from TSQLRecordNoCase or TSQLRecordCaseSensitive if you expect
// your text fields to contain only basic (un)accentued ASCCI characters, and
// to be opened by any standard/ SQlite3 library or tool (outside of
// SynSQLite3.pas/SynDBExplorer)
TSQLRecordNoCase = class(TSQLRecord)
protected
/// will call Props.SetCustomCollationForAll(sftUTF8Text,'NOCASE')
class procedure InternalDefineModel(Props: TSQLRecordProperties); override;
end;

/// root class for defining and mapping database records with case-sensitive
// BINARY collation
// - by default, any sftUTF8Text field (RawUTF8, UnicodeString, WideString
// properties) will use our Unicode SYSTEMNOCASE SQLite3 collation, which calls
// UTF8ILComp() to handle most western languages, but is not standard
// - you may inherit from this class to ensure any text field will use the
// faster and SQLite3 built-in BINARY collation, which is case-sensitive
// - inherit from TSQLRecordNoCase or TSQLRecordCaseSensitive if you expect
// your text fields to contain only basic (un)accentued ASCCI characters, and
// to be opened by any standard/ SQlite3 library or tool (outside of
// SynSQLite3.pas/SynDBExplorer)
TSQLRecordCaseSensitive = class(TSQLRecord)
protected
/// will call Props.SetCustomCollationForAll(sftUTF8Text,'BINARY')
class procedure InternalDefineModel(Props: TSQLRecordProperties); override;
end;

/// database records with NOCASE collation and JSON_OPTIONS_FAST_EXTENDED variants
TSQLRecordNoCaseExtended = class(TSQLRecordNoCase)
protected
/// will call Props.SetVariantFieldsDocVariantOptions(JSON_OPTIONS_FAST_EXTENDED);
class procedure InternalDefineModel(Props: TSQLRecordProperties); override;
end;

/// database records with BINARY collation and JSON_OPTIONS_FAST_EXTENDED variants
TSQLRecordCaseSensitiveExtended = class(TSQLRecordCaseSensitive)
protected
/// will call Props.SetVariantFieldsDocVariantOptions(JSON_OPTIONS_FAST_EXTENDED);
class procedure InternalDefineModel(Props: TSQLRecordProperties); override;
end;

/// allow on-the-fly translation of a TSQLTable grid value
// - should return valid JSON value of the given cell (i.e. quoted strings,
// or valid JSON object/array) unless HumanFriendly is defined
@@ -8567,11 +8593,11 @@ TSQLTable = class
function GetCSVValues(Tab: boolean; CommaSep: AnsiChar=',';
AddBOM: boolean=false; RowFirst: integer=0; RowLast: integer=0): RawUTF8; overload;
/// save the table in 'schemas-microsoft-com:rowset' XML format
// - this format is used by ADODB.recordset, easily consummed by MS apps
// - this format is used by ADODB.recordset, easily consumed by MS apps
// - see @https://synopse.info/forum/viewtopic.php?pid=11691#p11691
procedure GetMSRowSetValues(Dest: TStream; RowFirst,RowLast: integer); overload;
/// save the table in 'schemas-microsoft-com:rowset' XML format
// - this format is used by ADODB.recordset, easily consummed by MS apps
// - this format is used by ADODB.recordset, easily consumed by MS apps
// - see @https://synopse.info/forum/viewtopic.php?pid=11691#p11691
function GetMSRowSetValues: RawUTF8; overload;
/// save the table in Open Document Spreadsheet compressed format
// - similar to GetU() method, but for the current Step
function FieldAsRawUTF8(const FieldName: RawUTF8): RawUTF8; overload;
{$ifdef HASINLINE}inline;{$endif}
/// read-only access to a particular field value, as VCL String
// - raise an ESQLTableException if called outside valid Step() sequence
// - similar to GetString() method, but for the current Step
function FieldAsString(FieldIndex: Integer): String; overload;
{$ifdef HASINLINE}inline;{$endif}
/// read-only access to a particular field value, as VCL String
// - raise an ESQLTableException if called outside valid Step() sequence
// - similar to GetString() method, but for the current Step
function FieldAsString(const FieldName: String): String; overload;
{$ifdef HASINLINE}inline;{$endif}
{$ifndef NOVARIANTS}
/// read-only access to a particular field value, as a variant
// - raise an ESQLTableException if called outside valid Step() sequence
FastSetString(result,buf,StrLen(buf));
end;

function TSQLTable.FieldAsString(FieldIndex: Integer): String;
var buf: PUTF8Char;
begin
buf := FieldBuffer(FieldIndex);
UTF8DecodeToString(buf,StrLen(buf),result);
end;

function TSQLTable.FieldAsString(const FieldName: String): String;
var buf: PUTF8Char;
begin
buf := FieldBuffer(FieldName);
UTF8DecodeToString(buf,StrLen(buf),result);
end;

{$ifndef NOVARIANTS}
function TSQLTable.Field(FieldIndex: integer): variant;
begin
Props.SetCustomCollationForAll(sftUTF8Text,'NOCASE');
end;

{ TSQLRecordCaseSensitive }

class procedure TSQLRecordCaseSensitive.InternalDefineModel(
Props: TSQLRecordProperties);
begin
Props.SetCustomCollationForAll(sftUTF8Text,'BINARY');
end;

{ TSQLRecordNoCaseExtended }

class procedure TSQLRecordNoCaseExtended.InternalDefineModel(Props: TSQLRecordProperties);
Props.SetVariantFieldsDocVariantOptions(JSON_OPTIONS_FAST_EXTENDED);
end;

{ TSQLRecordCaseSensitiveExtended }

class procedure TSQLRecordCaseSensitiveExtended.InternalDefineModel(
Props: TSQLRecordProperties);
begin
inherited InternalDefineModel(Props); // set BINARY collation
Props.SetVariantFieldsDocVariantOptions(JSON_OPTIONS_FAST_EXTENDED);
end;


{ TSQLRecordPropertiesMapping }

@@ -433,7 +433,7 @@ TSynBigTable = class
// the associated content
// - in most cases, this TStream is just a wrapper around the memory mapped
// buffer in memory
// - the TStream must be consummed immediately, before any Pack or
// - the TStream must be consumed immediately, before any Pack or
// UpdateToFile method calls
// - the caller must Free the returned TStream instance
// - if the data is not already memory mapped (i.e. for files >= 2 GB)
@@ -591,7 +591,7 @@ TSynBigTableString = class(TSynBigTable)
// the associated content
// - in most cases, this TStream is just a wrapper around the memory mapped
// buffer in memory
// - the TStream must be consummed immediately, before any Pack or
// - the TStream must be consumed immediately, before any Pack or
// UpdateToFile method calls
// - the caller must Free the returned TStream instance
// - if the data is not already memory mapped (i.e. for files >= 2 GB)
function VersionInfo: RawUTF8;
/// returns a ready-to-use User-Agent header with exe name, version and OS
// - e.g. 'myprogram3.1.0.123W32'
// - here OS_INITIAL[] character is used to identify the OS, with '32'
// appended on 32-bit Windows
function UserAgent: RawUTF8;
/// returns the version information of a specified exe file as text
// - includes FileName (without path), Detailed and BuildDateTime properties
@@ -3139,7 +3139,7 @@ TPollAsynchSockets = class
// - if this method is called from a single thread, you should use
// a TSynThreadPool for any blocking process of OnRead events
// - otherwise, this method is thread-safe, and incoming packets may be
// consummed from a set of threads, and call OnRead with newly received data
// consumed from a set of threads, and call OnRead with newly received data
procedure ProcessRead(timeoutMS: integer);
/// one or several threads should execute this method
// - thread-safe handle of any outgoing packets
@@ -558,7 +558,7 @@ TSMEngine = class;
// in addition to the main function result), it shall return a JSON object,
// with parameter names for all var/out/result values, e.g.
// ! '{"first":1,"second":2,"result":3}'
// - this allows the function result to be consummed by the JavaScript as
// - this allows the function result to be consumed by the JavaScript as
// a regular JS value or object
// - corresponds to meJSON kind of callback method
TSMEngineMethodEventJSON = function(const This: TSMObject;
@@ -1 +1 @@
'1.18.5010'
'1.18.5011'

0 comments on commit e18422e

Please sign in to comment.