#101 mORMot 1 » how to parse post data which includes "&" as content? » 2012-09-26 06:17:23

profh
Replies: 3

using IE browser to post data to my server, i get a post data in Variable "InContent" as follow:

var1=value1&var2=a.php?varphp1=valuephp1&varphp2=valuephp2&var3=value3

the result i parsed as follow:

var1 = value1
var2 = a.php?varphp1=valuephp1
varphp2 = valuephp2
var3 = value3

but what i really need is:

var1 = value1
var2 = a.php?varphp1=valuephp1&varphp2=valuephp2
var3 = value3

the apache server can parse it correctly.
what should i do, thanks.

#103 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-07 09:53:56

yes, what i mean is that it returns false when i get the last 500 bytes,

the syntax is right just like above standard,because the previous segments are all correct.

#104 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-07 09:18:12

sorry,678 means the rang length,so i mean 12345,12345 + 678.

#105 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-07 03:09:43

thanks, and it s great.

another problem i can not understand is:

i download a file from server using many segments, the range of the last segment perhaps is 12345,678.
if i download the last segment with range of 12345,678, it returns fales, but if i use 12345,-1, it is ok.

BTW,it s terrific about http://blog.synopse.info/post/2012/09/0 … laboration

#106 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-05 16:31:04

procedure THttpApiServer.Execute;
var Req: PHTTP_REQUEST;
    ReqID: HTTP_REQUEST_ID;
    ReqBuf, RespBuf: TSockData;
    i: integer;
    flags, bytesRead, bytesSent: cardinal;
    Err: HRESULT;
    InCompressAccept: THttpSocketCompressSet;
    InContentLength, InContentLengthRead: cardinal;
    InContentLengthStr: TSockData;
    InContentEncoding, InAcceptEncoding: TSockData;
    OutContentEncoding: TSockData;
    InURL, InMethod, InHeaders, InContent, InContentType: TSockData;
    OutContent, OutContentType, OutCustomHeader, OutStatus: TSockData;
    OutContentTypeP: PAnsiChar absolute OutContentType;
    FileHandle: THandle;
    Resp: PHTTP_RESPONSE;
    BufRead: PAnsiChar;
    Heads: array of HTTP_UNKNOWN_HEADER;
    DataChunk: HTTP_DATA_CHUNK;

    rangstart,ranglength:int64;
  procedure getrangstartend;
  var
    i,ipos:integer;
    ssl:TStringlist;
    tmpstr:string;
  begin
    rangstart := 0;
    ranglength := -1;
    if (trim(inHeaders) = '') then exit;

    ssl := TStringlist.Create;
    ssl.Text := inHeaders;
    for i := 0 to ssl.Count -1 do
    begin
      tmpstr := trim(ssl.Strings[i]);
      if (pos('range:',lowercase(tmpstr)) = 1) then
      begin
        tmpstr := trim(copy(tmpstr,7,length(tmpstr) - 6));
        if (pos('bytes=',lowercase(tmpstr)) = 1) then
        begin
          tmpstr := trim(copy(tmpstr,7,length(tmpstr) - 6));
          ipos := pos('-',tmpstr);
          if (ipos > 0) then
          begin
            try
              rangstart := strtoint64(trim(copy(tmpstr,1,ipos - 1)));
            except
              rangstart := 0;
            end;
            try
              ranglength := strtoint64(trim(copy(tmpstr,ipos + 1,
                                           length(tmpstr) - ipos + 1)));
            except
              ranglength := -1;
            end;
            if (ranglength > rangstart) then
              ranglength := ranglength - rangstart
            else
              ranglength := -1;
          end
          else
          begin
            ranglength := -1;

            try
              rangstart := strtoint64(trim(tmpstr));
            except
              rangstart := 0;
            end;
          end;
        end;
      end;
    end;
    ssl.free;
  end;

  procedure SendError(StatusCode: cardinal; const ErrorMsg: string);
  begin
    Resp^.SetStatus(StatusCode,OutStatus,@DataChunk,TSockData(ErrorMsg));
    Http.SendHttpResponse(fReqQueue,Req^.RequestId,0,Resp^,nil,bytesSent);
  end;

begin

getrangstartend is not so good smile

#107 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-05 14:33:09

i got it...

here is the code i just modify:

          if OutContentType=HTTP_RESP_STATICFILE then begin
            // response is file -> let http.sys serve it (OutContent is UTF-8)
            FileHandle := FileOpen(
              {$ifdef UNICODE}UTF8ToUnicodeString{$else}Utf8ToAnsi{$endif}(OutContent),
              fmOpenRead or fmShareDenyNone);
            if PtrInt(FileHandle)<0 then
              SendError(404,SysErrorMessage(GetLastError)) else
            try
              DataChunk.DataChunkType := hctFromFileHandle;
              DataChunk.FromFileHandle.FileHandle := FileHandle;
              rangstart := 0;
              ranglength := -1;
              getrangstartend;
              DataChunk.FromFileHandle.ByteRange.StartingOffset.QuadPart := rangstart;
              Int64(DataChunk.FromFileHandle.ByteRange.Length.QuadPart) := ranglength; // to eof
              Resp^.EntityChunkCount := 1;
              Resp^.pEntityChunks := @DataChunk;
              Http.SendHttpResponse(fReqQueue,Req^.RequestId,1,Resp^,nil,bytesSent);
            finally
              FileClose(FileHandle);
            end;
          end else begin

getrangstartend is used to get rangstart and ranglength from inHeaders.
the flags of Http.SendHttpResponse is changed to 1 from 0.


and it works now.

thanks,ab.

#108 Re: mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-05 13:26:28

Here is what  i m learning about: http://xxm.sourceforge.net/

Perhaps "hsys" of it is what i m looking for...

#109 mORMot 1 » response part of file while OutContentType equals HTTP_RESP_STATICFILE » 2012-09-03 16:54:27

profh
Replies: 14

while using THttpApiServer, how to response part of file according to 'Range: bytes=***-***' in InHeaders?

thanks.

#110 Re: PDF Engine » emf2pdf » 2012-07-12 08:39:20

i sent an email including emf and pdf files to you last night,please check it.

#111 Re: PDF Engine » emf2pdf » 2012-07-11 10:46:11

i really appreciate.

with my own rtf and emf files, no exception raised any more,but:
1. in pdf file,no chinese word appears,if i switch to view this pdf document as text file,then all chinese words appear.
2. position of numeric word in the pdf is not exactally correct.

i send pdf files to you,pls check it: abouchez@magic.fr

#112 Re: PDF Engine » emf2pdf » 2012-07-10 15:50:16

yes, a big vague smile ,because i can not past picture or file here.

the exception line is:
     Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;

exception msg:
'Access violation at address 004626A7 in module 'Project1.exe'. Read of address 004B4000'

Are you sure the TTF file is a true outline font?

i m not sure,indeed.

#113 Re: PDF Engine » emf2pdf » 2012-07-10 14:21:38

i just try it,the chinese words of emf file are all generated into pdf file,but they can not display properly in pdf file.
during generate pdf file,some exceptions are fired near the following code of synpdf.pas:

constructor TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType);
......
    for i := 0 to aUnicodeTTF.fUsedWideChar.Count-1 do
    with aUnicodeTTF.fUsedWide[i] do
      if Glyph<>0 then
        Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;

#115 Re: mORMot 1 » about blob column » 2012-07-06 08:42:38

i see, and i will check it.

thanks a lot.

#116 Re: mORMot 1 » about blob column » 2012-07-06 06:45:44

here is my code refer syndb,

unit uzjsonquery;

interface

uses Classes,SysUtils, db,ZConnection,ZSqlProcessor,ZDataset,
    SQLite3, SynCommons,syndb,synoledb,SQLite3Commons;

type
  TZJsonQuery = class(TZQuery)
  private
  protected
    procedure ColumnsToJSON(WR: TJSONWriter);
    function  FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
  public
    function  FetchAllAsJSON(Expanded: boolean; ReturnedRowCount: PPtrInt=nil): RawUTF8;
  end;

implementation

procedure TZJsonQuery.ColumnsToJSON(WR: TJSONWriter);
var col: integer;
    blob: RawByteString;
    tmpstream:TMemoryStream;
begin
  if WR.Expand then WR.Add('{');

  for col := 0 to FieldCount - 1 do begin
    if WR.Expand then
      WR.AddFieldName(Fields[col].FieldName); // add '"ColumnName":'
    if Fields[col].IsNull then
      WR.AddShort('null') else
    case Fields[col].DataType of
      db.ftUnknown:     WR.AddShort('null');
      ftSmallint, ftInteger, ftWord,ftLargeint: WR.Add(Fields[col].AsInteger);
      ftFloat:WR.Add(Fields[col].AsFloat);
      db.ftCurrency: WR.AddCurr64(Fields[col].AsCurrency);
      db.ftDate, db.ftTime, db.ftDateTime: begin
        WR.Add('"');
        WR.AddDateTime(Fields[col].AsDateTime);
        WR.Add('"');
      end;
      ftMemo,ftstring,ftWideString: begin
        WR.Add('"');
        WR.AddJSONEscape(pointer(Fields[col].AsString));
        WR.Add('"');
      end;
      db.ftBlob: begin
        tmpstream := TMemoryStream.Create;
        try
          TBlobField(Fields[col]).SaveToStream(tmpstream);
          tmpstream.Position := 0;
          WR.WrBase64(tmpstream.Memory,tmpstream.Size,true);
        finally
          tmpstream.Free;
          tmpstream := nil;
        end;
      end;
      else raise ESQLDBException.CreateFmt('%s: Invalid ColumnType() %s',
        [ClassName,'']);
    end;
    WR.Add(',');
  end;
  WR.CancelLastComma; // cancel last ','
  if WR.Expand then WR.Add('}');
end;

function TZJsonQuery.FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
var W: TJSONWriter;
    col: integer;
begin
  result := 0;
  W := TJSONWriter.Create(JSON,Expanded,false);
  try
    SetLength(W.ColNames,FieldCount);//columncount
    for col := 0 to FieldCount-1 do
      W.ColNames[col] := FieldDefList.FieldDefs[col].Name;
    W.AddColumns;
    if Expanded then W.Add('[');
     
    First;
    while (not Eof) do
    begin
      ColumnsToJSON(W);
      W.Add(',');
      inc(result);

      Next;
    end;
    W.CancelLastComma; // cancel last ','
    W.Add(']');
    if not Expanded then W.Add('}');
    W.Add(#10);
    W.Flush;
  finally
    W.Free;
  end;
end;

function TZJsonQuery.FetchAllAsJSON(Expanded: boolean;
                            ReturnedRowCount: PPtrInt=nil): RawUTF8;
var Stream: TRawByteStringStream;
    RowCount: PtrInt;
begin
  Stream := TRawByteStringStream.Create;
  try
    RowCount := FetchAllToJSON(Stream,Expanded);
    if ReturnedRowCount<>nil then ReturnedRowCount^ := RowCount;
      
    result := Stream.DataString;
  finally
    Stream.Free;
  end;
end;

it is ok for me, and i hope it is usful for someone else.

#117 Re: mORMot 1 » about blob column » 2012-07-04 11:31:01

while using ZeosLib,another question is about json:

how to translate between ZeosLib's Query and json?

#118 Re: mORMot 1 » about blob column » 2012-07-04 10:09:49

i use sqlite3 and mysql at the same time.

and i used synpdf before,but it can not process chinese font from my emf file,so i pause now, and i shall pick up it later.

i post here before: http://synopse.info/forum/viewtopic.php?id=42

#119 Re: mORMot 1 » about blob column » 2012-07-04 09:17:55

how long shall the SynDBODBC.pas be finished? is it sutable for my case?
i really want use less third commponent.

thanks again.

#120 Re: mORMot 1 » about blob column » 2012-07-04 08:00:00

thanks,
perhaps i should use zeoslib at the server side as i used to.

#121 Re: mORMot 1 » about blob column » 2012-07-03 23:30:00

i use HeidiSQL 5.0.0.3272 and execute 'select blobfield from mytable where id=100',it can return one row with blobfield content,no error displays.

#122 Re: mORMot 1 » about blob column » 2012-07-03 23:26:01

ado and syndbexplorer are the same,
i try syndbexplorer ,if i use "select * from mytable where id = 100",it returns one row with the blobfield empty. if i use 'select blobfield from mytable where id=100',it makes a mistake and popup a error window. the error window just like this:

Error

OLEDB Error 80040E21 - ?? OLE DB
???????????,????? OLEDB ????????????

Exception class:EOleDBException

#123 Re: mORMot 1 » about blob column » 2012-07-03 14:00:55

it does not work,and also returns nothing.

the OleDB Provider i use is:mysql-connector-odbc-5.1.11-win32.msi.

#124 Re: mORMot 1 » about blob column » 2012-07-03 13:30:19

yes, it is a TEXT column,i use Query.ColumnUTF8(), and i also got nothing.

IMHO,Query.Execute('select blobfield from mytable where id=100',true) returns empty,
but 'select blobfield from mytable where id=100' does return one row.

#125 Re: mORMot 1 » about blob column » 2012-07-03 12:09:50

if Query.Step then
  aParams.Resp := Query.ColumnBlob(0)
else
  // no rows return

i check that Query.Step returns false.

but,'select blobfield from mytable where id=100' does return one row, and "blobfield" is text type of Mysql.

#126 Re: mORMot 1 » about blob column » 2012-07-03 09:11:13

i add step(true) or step(false) before "aParams.Resp := Query.ColumnBlob(0);",it is just the same problem.

i think 'select blobfield from mytable where id=100' makes the mistake,but it is really a correct SQL statement.

#127 mORMot 1 » about blob column » 2012-07-03 02:52:16

profh
Replies: 24

i retrieve blob data from database using TSQLDBStatement,but the Query.TotalRowsRetrieved is always zero:

var
  OleDBConnectionProperties:TOleDBConnectionProperties;
  SQLDBConnection:TSQLDBConnection;
  Query: TSQLDBStatement;
......

  OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
  OleDBConnectionProperties.ConnectionString := myrdbmstr;

  try
    SQLDBConnection := OleDBConnectionProperties.NewConnection;
  except
    OleDBConnectionProperties.Free;
    exit;
  end;

  try
    Query := SQLDBConnection.NewStatement;
  except
    SQLDBConnection.Disconnect;
    SQLDBConnection.Free;
    OleDBConnectionProperties.Free;
    exit;
  end;

  try
    Query.Execute('select blobfield from mytable where id=100',true);
    aParams.Resp := Query.ColumnBlob(0);
  except
    Query.Free;
    SQLDBConnection.Disconnect;
    SQLDBConnection.Free;
    OleDBConnectionProperties.Free;
    aParams.Resp := '';
    exit;
  end;

#128 Re: mORMot 1 » TSQLDBStatement.Execute can not execute in the windows service » 2012-06-15 09:12:56

thanks,ab,

it does work after using administrator user to run the service.

#129 Re: mORMot 1 » TSQLDBStatement.Execute can not execute in the windows service » 2012-06-14 11:00:06

use the following connectionstring,it works in a service:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\aa.mdb;Persist Security Info=False

BTW,with "Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource" connectionstring,i used "mysql-connector-odbc-5.1.11-win32" to connect mysql...

#130 mORMot 1 » TSQLDBStatement.Execute can not execute in the windows service » 2012-06-14 01:43:17

profh
Replies: 4

the following function can execute in a TForm ,but can not in a TService,why?

function execsql;
var
  OleDBConnectionProperties:TOleDBConnectionProperties;
  SQLDBConnection:TSQLDBConnection;
  Query: TSQLDBStatement;
begin
  result := false;

  OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
  OleDBConnectionProperties.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource';
  SQLDBConnection := OleDBConnectionProperties.NewConnection;
  Query := SQLDBConnection.NewStatement;
  try
    Query.Execute('insert into mytable(ccode) values(12345)',false);
  except
    Query.Free;
    exit;
  end;

  Query.Free;
  result := true;

end;

#131 Re: mORMot 1 » server cluster » 2012-06-08 12:08:47

i v got the exactly place of "hosting",and it is easy. tongue i mean it is not so easy to understand "hosting".
thanks again,and i will try once more...

#132 Re: mORMot 1 » server cluster » 2012-06-05 09:59:09

thanks,

got the documentation,but it seems not a piece of cake.

#133 mORMot 1 » server cluster » 2012-06-05 00:47:16

profh
Replies: 5

hi,ab

how to make many servers separately work together?

thanks.

#134 Re: mORMot 1 » delete many rows of TSQLRest with where condition » 2012-05-03 08:41:34

it s great,
BTW,i use TSQLRestServerStaticInMemory just for cache, for real database i also use TSQLRestServerDB...

many thanks for coblongpamor and ab.

#135 Re: mORMot 1 » delete many rows of TSQLRest with where condition » 2012-05-03 03:33:34

      dbcache := TSQLRestServerStaticInMemory.Create(TCache,nil,'');
      ......
      lastcache := 60 * 1000;
      tmpid := 1;
      Rec := TCache.Create(dbcache, 'id=%',[tmpid]);
      try
        tmpid := Rec.ID;
        cur64 := Rec.Time;
      finally
        Rec.Free;
      end;
      while (tmpid > 0) do
      begin
        if (cur64 < lastcache) then
        begin
          ab := dbcache.Delete(TCache,tmpid);
          if (not ab) then break;
        end else tmpid := tmpid + 1;

        Rec := TCache.Create(dbcache, 'id=%',[tmpid]);
        try
          tmpid := Rec.ID;
          cur64 := Rec.Time;
        finally
          Rec.Free;
        end;
      end;

it s ugly,but it works.
any good idea?

#136 mORMot 1 » delete many rows of TSQLRest with where condition » 2012-05-02 15:03:44

profh
Replies: 5

how to delete many rows  of TSQLRest with where condition?

thanks.

#137 Re: mORMot 1 » Interface based services » 2012-04-08 15:15:13

pls show an example about how to send/get binary data to/from server using an interface-based service.

thanks.

#139 Re: mORMot 1 » is it able to use post instead of get methord? » 2012-04-07 08:57:34

Would you change the code of function "TSQLRestClientURI.CallBackPut" in SQLite3Commons.pas:

from:
    ...
    result := URI(Model.getURICallBack(aMethodName,aTable,aID),
      'PUT',nil,aResponseHead,@aSentData).Lo;
    ...

to:
    ...
    result := URI(Model.getURICallBack(aMethodName,aTable,aID),
      'PUT',@aResponse,aResponseHead,@aSentData).Lo;
    ...

so as i can get aParams.Resp when i use CallBackPut.

#141 mORMot 1 » is it able to use post instead of get methord? » 2012-03-10 03:08:50

profh
Replies: 5

when TSQLite3HttpClient(Client).CallBackGetResult was called,httpserver got the aParams value using "GET" methord with "url",

is it able to use post instead of get methord,so httpserver gets the aParams value using "POST" methord with "incontent"?

sometimes the length limit is a problem.

#142 Re: mORMot 1 » how to convert RawUTF8 to TSQLRawBlob? » 2012-03-10 01:46:45

thanks,

What i exactly want to do is:
load/save binary data(TMemoryStream,not only Tsynpicture) from/into database.

i used bintohex and hextobin to convert between binary and RawUTF8, and then load/save  RawUTF8 from/into database,
sometimes i want to use TSQLRawBlob instead of RawUTF8...

#143 mORMot 1 » how to convert RawUTF8 to TSQLRawBlob? » 2012-03-09 13:53:25

profh
Replies: 3

i know how to use bintohex,but can not use hextobin to convert RawUTF8 to TSQLRawBlob.

any one any help?
thanks.

#144 Re: mORMot 1 » Client-Server remote access to any method (DataSnap-like) » 2012-02-17 01:29:04

i just add a timer1 to the Project04Client of "04 - HTTP Client-Server" and the following script:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  FindButton.Click;
end;

#145 Re: mORMot 1 » Client-Server remote access to any method (DataSnap-like) » 2012-02-16 17:38:38

excise is ok,samples9 , sample6 and sample4 are all built into one, and the server side uses just one ip address and one port.
but the memory keeps increasing...

for samples4,add a timer event with the following script:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  FindButton.Click;
end;

add a big text record and then fire the Timer1,the Project04Server.exe memory keeps increasing...

#147 Re: mORMot 1 » Client-Server remote access to any method (DataSnap-like) » 2012-02-10 10:00:05

thanks.

sample04 and sample06 are all fine.
i hope sample6 with HTTP but no named pipe,not just sample4.
it is better if samples9 , sample6 and sample4 are all built into one, and the server side uses just one ip address and one port.

#148 Re: mORMot 1 » Client-Server remote access to any method (DataSnap-like) » 2012-02-10 07:23:49

how to implement it using HTTP ,without named pipe?

#149 mORMot 1 » about http client/server » 2011-11-23 09:43:03

profh
Replies: 1

sorry for my poor english.

i compiled project04 and it run successful.

i run project04server.exe on my computer and a remote computer respectively,with "add the message",project04client.exe connected to the remote server run little faster. on the other hand,with "find a previous message",project04client.exe connected to my computer server run much faster.

how does the network affect the effect?

#150 Re: PDF Engine » emf2pdf » 2010-07-17 02:46:20

many many thanks,ab

update the source code,two problems are still remained:
1. the text position is not exactly right, all arranged on the upper left corner.
2. many more text does appear, but a few part of content is still not appeared.

Board footer

Powered by FluxBB