#1 Re: mORMot 1 » function DataSetToJSON(Data: TDataSet): RawUTF8 » 2016-04-26 16:36:00

function DataSetToJSON(Data: TDataSet): RawUTF8 [ original ]

function DataSetToJSON(Data: TDataSet; const RecNo:Integer=0): RawUTF8; [changed]

I have add the const RecNo:Integer=0

#2 mORMot 1 » function DataSetToJSON(Data: TDataSet): RawUTF8 » 2016-04-26 11:55:24

big.rid
Replies: 2
function DataSetToJSON(Data: TDataSet; const RecNo:Integer=0): RawUTF8;
var W: TJSONWriter;
    f: integer;
    blob: TRawByteStringStream;
begin
  result := 'null';
  if Data=nil then
    exit;
  if (RecNo=0) then
    Data.First;
  if Data.Eof then
    exit;
  W := TJSONWriter.Create(nil,true,false);
  try
    // get col names and types
    SetLength(W.ColNames,Data.FieldCount);
    for f := 0 to high(W.ColNames) do
      StringToUTF8(Data.FieldDefs[f].Name,W.ColNames[f]);
    W.AddColumns;
    if (RecNo=0) then
      W.Add('[');
    repeat
      W.Add('{');
      for f := 0 to Data.FieldCount-1 do begin
        W.AddString(W.ColNames[f]);
        with Data.Fields[f] do
        if IsNull then
          W.AddShort('null') else
        case DataType of
        ftBoolean:
          W.Add(AsBoolean);
        ftSmallint, ftInteger, ftWord, ftAutoInc:
          W.Add(AsInteger);
        ftLargeint:
          W.Add(TLargeintField(Data.Fields[f]).AsLargeInt);
        ftFloat, ftCurrency: // TCurrencyField is sadly a TFloatField
          W.Add(AsFloat,TFloatField(Data.Fields[f]).Precision);
        ftBCD:
          W.AddCurr64(AsCurrency);
        ftFMTBcd:
          AddBcd(W,AsBCD);
        ftTimeStamp, ftDate, ftTime, ftDateTime: begin
          W.Add('"');
          W.AddDateTime(AsDateTime);
          W.Add('"');
        end;
        ftString, ftFixedChar, ftMemo: begin
          W.Add('"');
          W.AddAnsiString({$ifdef UNICODE}AsAnsiString{$else}AsString{$endif},
            twJSONEscape);
          W.Add('"');
        end;
        ftWideString: begin
          W.Add('"');
          W.AddJSONEscapeW(pointer(TWideStringField(Data.Fields[f]).Value));
          W.Add('"');
        end;
        ftVariant:
          W.AddVariant(AsVariant);
        ftBytes, ftVarBytes, ftBlob, ftGraphic, ftOraBlob, ftOraClob: begin
          blob := TRawByteStringStream.Create;
          try
            (Data.Fields[f] as TBlobField).SaveToStream(blob);
            W.WrBase64(pointer(blob.DataString),length(blob.DataString),true);
          finally
            blob.Free;
          end;
        end;
        {$ifdef ISDELPHI2007ANDUP}
        ftWideMemo, ftFixedWideChar: begin
          W.Add('"');
          W.AddJSONEscapeW(pointer(AsWideString));
          W.Add('"');
        end;
        {$endif}
        {$ifdef UNICODE}
        ftShortint, ftByte:
          W.Add(AsInteger);
        ftLongWord:
          W.AddU(TLongWordField(Data.Fields[f]).Value);
        ftExtended:
          W.Add(AsFloat,DOUBLE_PRECISION);
        ftSingle:
          W.Add(AsFloat,SINGLE_PRECISION);
        {$endif}
        else W.AddShort('null'); // unhandled field type
        end;
        W.Add(',');
      end;
      W.CancelLastComma;
      W.Add('}',',');
      if (RecNo=0) then Data.Next else break;
    until (Data.Eof);
    W.CancelLastComma;
    if (RecNo=0) then
      W.Add(']');
    W.SetText(result);
  finally
    W.Free;
  end;
end;

What do you think ?

#3 Re: mORMot 1 » Firebird connectivity using TODBCConnectionProperties » 2014-08-14 21:26:25

  aProps := TSQLDBZEOSConnectionProperties.Create(
            TSQLDBZEOSConnectionProperties.URI(
            dFirebird,
            'localhost:3055',
            'C:\fbclient.dll',
            False), '3camadas', 'SYSDBA', 'masterkey');
  aModel_Usuarios      := TSQLModel.Create([TUsuarios], 'usuarios');
  aRestServer_Usuarios := TSQLRestServer.Create(aModel_Usuarios, False);
  aHttpServer          := TSQLHttpServer.Create('8080',[aRestServer_Usuarios], '+', useHttpApiRegisteringURI);
  VirtualTableExternalRegisterAll(aModel_Usuarios, aProps);

is correct ?

http://localhost:8080/usuarios -> in chrome

{
"ErrorCode":400,
"ErrorText":"Bad Request"
}

#5 Re: mORMot 1 » Firebird connectivity using TODBCConnectionProperties » 2014-08-14 12:46:51

procedure TForm5.BitBtn2Click(Sender: TObject);
var
  pr : TSQLDBZEOSConnectionProperties;
  cn : TSQLDBZEOSConnection;
begin
  pr := TSQLDBZEOSConnectionProperties.Create(
  TSQLDBZEOSConnectionProperties.URI(
  dFirebird,
  'localhost/3055',
  'c:\Firebird_2_5\bin\fbclient.dll',
  false), '3camadas', 'sysdba', 'masterkey');
  cn := TSQLDBZEOSConnection.Create(pr);
  cn.Connect; //Error[1]
end;

[1] EZSQLException with message 'SQL Error: connection rejected by remote interface. Error code: -923. Connection not established'.

#6 Re: mORMot 1 » Firebird connectivity using TODBCConnectionProperties » 2014-08-12 12:48:51

Does anyone have an example of connecting to firebird using SynDBFirebird?

Board footer

Powered by FluxBB