mORMot and Open Source friends
Check-in [28cbca75fd]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:{5170} fixed TSQLRest.OneFieldValues - as reported by Lagodny
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 28cbca75fdd722a128af2b3492d673d122cd88a0
User & Date: ab 2019-04-12 08:01:53
Context
2019-04-12
09:45
{5171} slightly refactored UnCamelCase() check-in: 591e342dd1 user: ab tags: trunk
08:01
{5170} fixed TSQLRest.OneFieldValues - as reported by Lagodny check-in: 28cbca75fd user: ab tags: trunk
2019-04-11
16:35
{5169} fixed latest commit on some targets check-in: 0838abde35 user: ab tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ReadMe.txt.

34
35
36
37
38
39
40

41
42
43
44
45
46
47
  Eva Freimann (EVaF)
  F-Vicente
  Goran Despalatovic (gigo)
  Jean-Baptiste Roussia (jbroussia)
  Joe (jokusoft)
  Johan Bontes
  Jordi Tudela

  Leon Oosthuizen
  Maciej Izak (hnb)
  Mario Moretti
  Marius Maximus (mariuszekpl)
  Martin Eckes
  Martin Suer
  Mazinsw






>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  Eva Freimann (EVaF)
  F-Vicente
  Goran Despalatovic (gigo)
  Jean-Baptiste Roussia (jbroussia)
  Joe (jokusoft)
  Johan Bontes
  Jordi Tudela
  Lagodny
  Leon Oosthuizen
  Maciej Izak (hnb)
  Mario Moretti
  Marius Maximus (mariuszekpl)
  Martin Eckes
  Martin Suer
  Mazinsw

Changes to SQLite3/mORMot.pas.

35
36
37
38
39
40
41

42
43
44
45
46
47
48
.....
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
.....
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100

36101
36102
36103
36104
36105
36106

36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
    DigDiver
    EgorovAlex
    Emanuele (lele9)
    Esmond
    Goran Despalatovic (gigo)
    Jordi Tudela
    Jean-Baptiste Roussia (jbroussia)

    Maciej Izak (hnb)
    Martin Suer
    Michalis Kamburelis
    MilesYou
    Ondrej
    Pavel (mpv)
    Sabbiolina
................................................................................
  end;
end;

procedure TSQLTable.IDArrayToBits(var Bits; var IDs: TIDDynArray);
var i,FID: integer;
    U: PPUTF8Char;
    ID: Pointer;
    IDn: integer;
//    AllID: : TIDDynArray;
begin
  if length(IDs)=fRowCount then begin // all selected -> all bits set to 1
    {$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,255);
    exit;
  end;
  {$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,0);
  if IDs=nil then
    exit; // no selected -> all bits left to 0
  // we sort IDs to use FastFindIntegerSorted() and its O(log(n)) binary search
  ID := @IDs[0];
  IDn := high(IDs);
  QuickSortInt64(ID,0,IDn);
  if not Assigned(fIDColumn) then begin
    FID := fFieldIndexID; // get ID column field index
    if FID<0 then
      exit; // no ID column -> unable to get bit index
  end else
    FID := 0; // make compiler happy
  if Assigned(fIDColumn) then begin
    for i := 1 to fRowCount do
      if FastFindInt64Sorted(ID,IDn,GetInt64(fIDColumn[i]))>=0 then
        SetBitPtr(@Bits,i-1);
  end else begin
    U := @fResults[FID+FieldCount];  // U^ = ID column UTF-8 content
    for i := 0 to fRowCount-1 do begin
      if FastFindInt64Sorted(ID,IDn,GetInt64(U^))>=0 then
        SetBitPtr(@Bits,i);
      inc(U,FieldCount);
    end;
  end;
{  // debugg:
  IDArrayFromBits(Bits,AllID);
  assert(length(AllID)=length(IDs));
................................................................................
  try
    if (T.FieldCount<>1) or (T.fRowCount<=0) then
      exit;
    // calculate row values CSV needed memory
    SetLength(Lens,T.fRowCount);
    SepLen := length(Separator);
    Len := 0;
    for i := 0 to T.fRowCount-1 do begin // ignore fResults[0] i.e. field name
      Lens[i] := StrLen(T.fResults[i]);
      inc(Len,Lens[i]+SepLen);

    end;
    dec(Len,SepLen);
    SetLength(result,Len);
    // add row values as CSV
    P := pointer(result);
    for i := 1 to T.fRowCount do begin

      L := Lens[i-1];
      if L<>0 then begin
        {$ifdef FPC}Move{$else}MoveFast{$endif}(T.fResults[i]^,P^,L);
        inc(P,L);
      end;
      if i=T.fRowCount then
        break;
      {$ifdef FPC}Move{$else}MoveFast{$endif}(pointer(Separator)^,P^,SepLen);
      inc(P,SepLen);
    end;
    //assert(P-pointer(result)=Len);
  finally
    T.Free;
  end;
end;

function TSQLRest.OneFieldValues(Table: TSQLRecordClass; const FieldName,






>







 







|











|
|








|




|







 







|
|
|
>





|
>









|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
.....
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
.....
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
    DigDiver
    EgorovAlex
    Emanuele (lele9)
    Esmond
    Goran Despalatovic (gigo)
    Jordi Tudela
    Jean-Baptiste Roussia (jbroussia)
    Lagodny
    Maciej Izak (hnb)
    Martin Suer
    Michalis Kamburelis
    MilesYou
    Ondrej
    Pavel (mpv)
    Sabbiolina
................................................................................
  end;
end;

procedure TSQLTable.IDArrayToBits(var Bits; var IDs: TIDDynArray);
var i,FID: integer;
    U: PPUTF8Char;
    ID: Pointer;
    IDmax: integer;
//    AllID: : TIDDynArray;
begin
  if length(IDs)=fRowCount then begin // all selected -> all bits set to 1
    {$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,255);
    exit;
  end;
  {$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,0);
  if IDs=nil then
    exit; // no selected -> all bits left to 0
  // we sort IDs to use FastFindIntegerSorted() and its O(log(n)) binary search
  ID := @IDs[0];
  IDmax := high(IDs);
  QuickSortInt64(ID,0,IDmax);
  if not Assigned(fIDColumn) then begin
    FID := fFieldIndexID; // get ID column field index
    if FID<0 then
      exit; // no ID column -> unable to get bit index
  end else
    FID := 0; // make compiler happy
  if Assigned(fIDColumn) then begin
    for i := 1 to fRowCount do
      if FastFindInt64Sorted(ID,IDmax,GetInt64(fIDColumn[i]))>=0 then
        SetBitPtr(@Bits,i-1);
  end else begin
    U := @fResults[FID+FieldCount];  // U^ = ID column UTF-8 content
    for i := 0 to fRowCount-1 do begin
      if FastFindInt64Sorted(ID,IDmax,GetInt64(U^))>=0 then
        SetBitPtr(@Bits,i);
      inc(U,FieldCount);
    end;
  end;
{  // debugg:
  IDArrayFromBits(Bits,AllID);
  assert(length(AllID)=length(IDs));
................................................................................
  try
    if (T.FieldCount<>1) or (T.fRowCount<=0) then
      exit;
    // calculate row values CSV needed memory
    SetLength(Lens,T.fRowCount);
    SepLen := length(Separator);
    Len := 0;
    for i := 1 to T.fRowCount do begin
      L := StrLen(T.fResults[i]); // ignore fResults[0] i.e. field name
      inc(Len,L+SepLen);
      Lens[i-1] := L;
    end;
    dec(Len,SepLen);
    SetLength(result,Len);
    // add row values as CSV
    P := pointer(result);
    i := 1;
    repeat
      L := Lens[i-1];
      if L<>0 then begin
        {$ifdef FPC}Move{$else}MoveFast{$endif}(T.fResults[i]^,P^,L);
        inc(P,L);
      end;
      if i=T.fRowCount then
        break;
      {$ifdef FPC}Move{$else}MoveFast{$endif}(pointer(Separator)^,P^,SepLen);
      inc(P,SepLen);
    until false;
    //assert(P-pointer(result)=Len);
  finally
    T.Free;
  end;
end;

function TSQLRest.OneFieldValues(Table: TSQLRecordClass; const FieldName,

Changes to SynCrtSock.pas.

249
250
251
252
253
254
255

256
257
258
259
260
261
262
....
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
  {$endif}
{$else MSWINDOWS}
  {$undef USEWININET}
  {$ifdef FPC}
  SynFPCSock,
  SynFPCLinux,
  BaseUnix, // for fpgetrlimit/fpsetrlimit

  {$else}
  {$ifndef DELPHI5OROLDER}
  Types,
  {$endif}
  {$endif}
  {$ifdef KYLIX3}
  KernelIoctl, // for IoctlSocket/ioctl FION* constants
................................................................................
  t64 := GetTickXP; // (almost) atomic read
  if t32<t64.Lo then
    inc(t64.Hi); // wrap-up overflow after 49 days
  t64.Lo := t32;
  GetTickXP := t64; // (almost) atomic write
end; // warning: FPC's GetTickCount64 doesn't handle 49 days wrap :(
{$else}
function GetTick64: Int64; {$ifdef HASINLINE}inline;{$endif}
begin
  result := GetTickCount64; // will use SynFPCLinux/SynKylix.GetTickCount64
end;
{$endif MSWINDOWS}

function TCrtSocket.TrySndLow(P: pointer; Len: integer): boolean;
var sent, err: integer;
    endtix: Int64;
begin






>







 







|

|







249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
....
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
  {$endif}
{$else MSWINDOWS}
  {$undef USEWININET}
  {$ifdef FPC}
  SynFPCSock,
  SynFPCLinux,
  BaseUnix, // for fpgetrlimit/fpsetrlimit
  Linux,
  {$else}
  {$ifndef DELPHI5OROLDER}
  Types,
  {$endif}
  {$endif}
  {$ifdef KYLIX3}
  KernelIoctl, // for IoctlSocket/ioctl FION* constants
................................................................................
  t64 := GetTickXP; // (almost) atomic read
  if t32<t64.Lo then
    inc(t64.Hi); // wrap-up overflow after 49 days
  t64.Lo := t32;
  GetTickXP := t64; // (almost) atomic write
end; // warning: FPC's GetTickCount64 doesn't handle 49 days wrap :(
{$else}
function GetTick64: Int64;
begin
  result := {$ifdef FPC}SynFPCLinux.{$endif}GetTickCount64;
end;
{$endif MSWINDOWS}

function TCrtSocket.TrySndLow(P: pointer; Len: integer): boolean;
var sent, err: integer;
    endtix: Int64;
begin

Changes to SynopseCommit.inc.

1
'1.18.5169'
|
1
'1.18.5170'