You are not logged in.
I've introduced TSingleDynArray, recognized as such in JSON serialization.
May help your work with "array of single" fields.
sorry, I can't find TSingleDynArray, which unit is it ?
My data structure include more TSQLRAWBlob( Dynamic Arrays) type in database. Let me think how to solve it. thanks a lot!
In mORMot Framework, when creating, you only use double type, why don't use single type; sometimes using double type data will need more storage capacity.
thanks a lot, as you said, now it's ok.:)
As I wrote above, I guess you didn't delete your previous database file, and time values are still encoded as text, not as Int64 TTImeLog values.
And your overriden InitializeTable is wrong: it should be declared as a CLASS PROCEDURE not only a PROCEDURE.
yeah, my version is 1.12
now as your above ,now the Querysql can work.
but the creatindex can't override.
type
TSQLSampleRecord = class(TSQLRecord)
private
fQuestion: RawUTF8;
fName: RawUTF8;
fTime: TTimeLog;//TDatetime;
fWave: TSQLRawBlob;
published
property Time: TTimeLog read fTime write fTime;
property Name: RawUTF8 read fName write fName stored false; //made Unique
property Question: RawUTF8 read fQuestion write fQuestion;
property Wave: TSQLRawBlob read fWave write fWave;
public
function DataAsHex(aClient: TSQLRestClientURI): RawUTF8;
class procedure InitializeTable(Server: TSQLRestServer; const FieldName: ShortString);override;
end;
implementation
//..
class procedure TSQLSamplerecord.InitializeTable(Server: TSQLRestServer; const FieldName: ShortString);
begin
if (FieldName[0]=#0) or IdemPropName(FieldName,'time') then
Server.CreateSQLIndex(self,'time',false);
end;
the Error is [DCC Error] SampleData.pas(71): E2070 Unknown directive: 'override'
what's the wrong ,i am fused with it.
You should better code, to use prepared statements and the more easy to read FormatUTF8() function:
sqlwhere := FormatUTF8('time>=:(%): and time<=:(%):',[Iso8601FromDateTime(Dtstart),Iso8601FromDateTime(Dtend)]);
but yes, this is perfectly possible.
And if you create an index over the time column, results will be immediate.
The right way of creating an index is to override the InitializeTable method of the class (so that it will be created automatically at table creation):class procedure TSQLSamplerecord.InitializeTable(Server: TSQLRestServer; const FieldName: ShortString); begin if (FieldName[0]=#0) or IdemPropName(FieldName,'time') then Server.CreateSQLIndex(self,'time',false); end;
when i override the procedure InitializeTable,there is an error:
TSQLSampleRecord = class(TSQLRecord)
private
fQuestion: RawUTF8;
fName: RawUTF8;
fTime: TTimeLog;//TDatetime;
fWave: TSQLRawBlob;
published
property Time: TTimeLog read fTime write fTime;
property Name: RawUTF8 read fName write fName stored false; //made Unique
property Question: RawUTF8 read fQuestion write fQuestion;
property Wave: TSQLRawBlob read fWave write fWave;
public procedure InitializeTable(Server: TSQLRestServer; const FieldName: ShortString);override;
end;
implementation
//..
procedure TSQLSampleRecord.InitializeTable(Server: TSQLRestServer; const FieldName: ShortString);override;
begin
if (FieldName[0]=#0) or IdemPropName(FieldName,'time') then
Server.CreateSQLIndex(self,'time',false);
end;
[DCC Error] SampleData.pas(30): E2037 Declaration of 'InitializeTable' differs from previous declaration
[DCC Error] SampleData.pas(71): E2070 Unknown directive: 'override'
[DCC Error] SampleData.pas(74): E2250 There is no overloaded version of 'CreateSQLIndex' that can be called with these arguments
i have redefinde the field time as TtimeLog,now
st:TDatetime;
st:=trunc(Datetimepicker1.Date)+Frac(Datetimepicker2.Time);//st:=20110128 09:16:27
QJson:=Database.List([TSQLSamplerecord],'*',FormatUTF8('time=:(%):',[Iso8601FromDateTime(st)]));//time=134959502363
..
do you guess what's the result of Json.rowcount?
it's 6816 ,which is all rows ,in fact it's only 1 row
and i trace the FquerySqL : 'select id,time,Name,Question from Samplerecord where time=:(134959502363):;'
why?
when i wirte realtime table into the Server by the Client side .and at the same time i want to open the DB with The SQLite Spy tool,sometimes the Error Message is Database is locked or NOt an Error.
i guess it is that i open the DB frequently?
thanks a lot,
sir,
do you have time to write a new example about how use the TSQLManyRecord. i make the project based on Client/Server,(httpClient and HttpServer).
Server Side have Realtime table(Memorytable) and historical table.
there are 3 Clients or more,and every Client Side only have one temporary table about 100 records and write individual 100 records to Server realtime table.Now
i don't know how to select all realtime records from Realtime table and store them into Historical table ,i want to store data every 3 seconds.
i don't know whether or not use the TSQLManyRecord Class,and if i can, how to build the system struct.now i am empty and confused with this.
table fields
TSQLSampleRecord = class(TSQLRecord)
private
fDescription: RawUTF8;
fName: RawUTF8;
fWave: TSQLRawBlob;
fTime: TTimeLog;//TDatetime;
published
property Description: RawUTF8 read fDescription write fDescription;
property Name: RawUTF8 read fName write fName ;
property Wave: TSQLRawBlob read fWave write fWave;//store Float array[0..2047]
property Time: TTimeLog read fTime write fTime;,
public
function WaveAsstring(aClient: TSQLRestClientURI): RawUTF8;//web dev.
end;
Can you give me some 'Crazy idea',:)
I have check the framework code but I cannot found BeginTransaction function for database object...
I think I don't understand your last post.
when on client user add more records or update more records ,the table is locked,other user can't get records.
in this Framework
database.Transactionbegin(TSQLTableclass)
beginTransaction is in order to inform the Table to do something
commitTransaction is in order to ENd your opening the table,
in this Framework
Database.commit
sometimes the Rollback is used .
if i use the TTimelog type, for example ,there are two TDatetime :Dtstart,Dtend; if i want to query the table with time>=Dtstart and time<=Dtend,
whether or not i can directly use
sqlwhere='time='+IntToStr(Iso8601FromDateTime(Dtstart))+' and '+'time='+IntToStr(Iso8601FromDateTime(Dtend));
QJson:=Database.List([TSQLSamplerecord],'*',sqlwhere);
yeah,you are right,i'm using first type。In fact ,our project used Int64 type about Time.i want to translate it into your framwok.i did't fint TTimelog type in your TTimelog. now i can try to use it. and i think the TTimelog(int64) type is best way to store time event.
thanks a lot
var
QJson:TSQLTableJSON;
st:TDatetime;
sqlwhere:RAWUTF8 ;
begin
st:=trunc(Datetimepicker1.Date)+Frac(Datetimepicker2.Time);
QJson:=Database.List([TSQLSamplerecord],'*','time='+DateTimeToIso8601(st,true,'T'));
if QJson<>nil then
try
edit3.Text:=inttostr(QJson.RowCount);
finally
qJson.Free;
end;
end;
in my table there is one field 'Time',like time ='2011-01-24T10:47:30', the result is no. i don't know what's the matter。
ok.now it works.
i downloaded the newest version, when i compiled the 04 example, the error is
[DCC Error] SQLite3.pas(1674): E1026 File not found: 'sqlite3.obj'
sir:
i want to know whether or not the DB capacity can oversize 2 TB (bytes) in your Framework
i add one new function addCSV(values:array of single,formatsetting:string),JSONEncodeArray(Values: array of single, formatsetting, TempMemoryStream: TMemoryStream=nil);
so i have solved my problem. thanks a lot,
i see that i need to spare more time in study your Framework Codes.
thanks a lot
longge007 wrote:about the GDIPages, in the example testSQLite3Page ,
in the top Line DrawText(), i changed it with DrawText('中国汉字'+InttoStr(i))' // Chinese Text
the PDF file can't dispaly Chinese Text rightly,You are using Delphi 2007 I guess?
This code will work under Delphi 2010.But it should work under Delphi 2007, if you don't use SQlite3i18n unit. It uses row VCL Canvas methods.
Do you use this unit?
If you use it, you'll have to set the main language to Chinese, to set the global CharSet for the VCL.
yeah,i am using Delphi2007, can you say details about how to use One Way: row VCL Canvas Methods and the second way:if i use SQLite3i18n unit,and how to set the Main Language to Chinese,to set the gloal Chart for the VCL.. i am Puzzled with The SQlite3Pages unit and SynPdf unit and SynGDIPlus unit.
i think if SQLite3Page is powerfula and easy to create a report in project. thanks your hard work!
yeah,Through the published ,the debugger is working, thanks a lot.
Sir, In fact ,my codes can work well all the time,the return error is for the Sigle to double.
for my client add procedue ,define the values is Array of single. however in the Server i use the JsonEncodeArray () which only handle Double type Array.i use the Values ( Array of double). finally, the return JsonArray is wrong.
perhaps, you should and one new function like add( value: single, decimals). not only add( value:double,decimals).
In HttpServer side, i add the breakpoint in the DataasHex, it does't work, so i don't know whether or not there is Degger swtich in the Server.
longge007 wrote:OK,about the JSONEncodeArray(),next is my codes,
You've some architectural problems in your code (like using a TSQLRestClient in the table definition). But it's not an issue, it's just that it's not following the n-tier separation.
You didn't post the Client-side here...
So what is your problem, i.e. how do you access to the data, what is the returned JSON content, etc...
.
about the Client ,i have post the Add procedure Codes. in Fact, i use retrieveBlob() method ,i can get the right Values that shows i have saved the Values(array of single) in the table blob field.
now i only hope the DataasHex Method can return the right JSONArray in the http request.Unfortunly, now it's wrong .Moreever you can write a test, add the values(array of single) by the Client.and then visit it in the http request, whether or not get the right JSONArray fomat.
perhaps you can look at this post.
http://synopse.info/forum/viewtopic.php?id=87
OK. I have solve my problem now the demo works. However I don't understant why you need integrated TMS component with your framework. Why don't you create a stand alone framework with a good demo with visual (and common) VCL?
yeah,i only think the TMScomponent is good in special SKIN ,not other need.
about the GDIPages, in the example testSQLite3Page ,
.....
DrawTitle(edt1.Text,true);
for i := 1 to 10 do
DrawText('This is some text '+IntToStr(i));
NewLine;
...///
in the top Line DrawText(), i changed it with DrawText('中国汉字'+InttoStr(i))' // Chinese Text
the PDF file can't dispaly Chinese Text rightly,
OK,about the JSONEncodeArray(),next is my codes,
//TSQLRecord
TSQLSampleRecord = class(TSQLRecord)
private
fQuestion: RawUTF8;
fName: RawUTF8;
fTime: TDatetime;
fWave: TSQLRawBlob;
published
property Time: TDatetime read fTime write fTime;
property Name: RawUTF8 read fName write fName stored false; //made Unique
property Question: RawUTF8 read fQuestion write fQuestion;
property Wave: TSQLRawBlob read fWave write fWave;
public
function DataAsHex(aClient: TSQLRestClientURI): RawUTF8;
end;
the add procedue In Client
procedure TForm1.AdvGlowButton5Click(Sender: TObject);
var Rec: TSQLSampleRecord;
i,n:integer;
aWave:array of single;
tempstream:tMemorystream;
begin
n:=1024;
setLength(aWave,n);
for i := 0 to n - 1 do
aWave[i]:=100*sin(i*20+110);
tempstream:=TMemoryStream.Create;
Tempstream.Write(AWave[0], (High(aWave) + 1) * SizeOf(Single));
Rec := TSQLSampleRecord.Create;
try
Rec.Time := Now;
count:=count+1;
// we use explicit StringToUTF8() for conversion below
// a real application should use TLanguageFile.StringToUTF8() in SQLite3i18n
Rec.Name := StringToUTF8(NameEdit.Text);
Rec.Question := StringToUTF8(QuestionMemo.Text);
if Database.Add(Rec,true)=0 then
ShowMessage('Error adding the data') else begin
NameEdit.Text := '';
QuestionMemo.Text := '';
NameEdit.SetFocus;
end;
if Database.UpdateBlob(TSQLSamplerecord,rec.ID,'Wave',TempStream) then
statusbar1.Panels[1].Text:=Inttostr(Rec.id)+'条Blob';
finally
Rec.Free;
Tempstream.Free;
aWave:=nil;
end;
end;
the new TSQLRestServer class
type
TSQLRestServerWave=class(TSQLRestServerDB)
function DataAsHex(aRecord: TSQLSampleRecord; aParameters: PUTF8Char;
const aSentData: RawUTF8; var aResp, aHead: RawUTF8): Integer;
end;
........
function TSQLRestServerWave.DataAsHex(aRecord: TSQLSampleRecord; aParameters: PUTF8Char; const aSentData: RawUTF8; var aResp: RawUTF8; var aHead: RawUTF8):integer;
var aData: TSQLRawBlob;
Values:Array of double;
begin
result := 404; // invalid Request
if (self=nil) or (aRecord=nil) or not aRecord.InheritsFrom(TSQLRecord) or
(aRecord.ID<0) then
exit; // we need a valid record and its ID
if not RetrieveBlob(TSQLSampleRecord,aRecord.ID,'Wave',aData) then
exit; // impossible to retrieve the Data BLOB field
setLength(Values,Length(aData) div 4);
Move(pointer(aData)^,Values[0],Length(aData));
//aResp := JSONEncodeResult([SynCommons.BinToHex(aData)]);
aResp:=JSONEncodeArray(Values,3);
// idem: aResp := JSONEncode(['result',BinToHex(aRecord.fData)],TempMemoryStream);
result := 200; // success
end;
the GDIPlus can't handle Chinese Font. can you tell me where is the Font transfer in thsi *.pas. perhaps i can do more for the Chinese font convertion in PDF report
sir:
In last Version 1.91.i test it.
can you test the function JSONENCODEArray(). i add the Values :Array of Single. and the retriveblob processing is right
now define new TSQLRestServer added DataasHex function . when the Client http://127.0.0.1/root...,it can't return right JSONArray structure.or give me some quesiton,how to save the Values( Array of single).
yeah, i have downloaded the New version 1.9 and now is using it (8.19 newest version).
look at my codes Dataashex
function TSQLRestServerWave.DataAsHex(aRecord: TSQLSampleRecord; aParameters: PUTF8Char; const aSentData: RawUTF8; var aResp: RawUTF8; var aHead: RawUTF8):integer;
var aData: TSQLRawBlob;
Values:Array of double;
begin
result := 404; // invalid Request
if (self=nil) or (aRecord=nil) or not aRecord.InheritsFrom(TSQLRecord) or
(aRecord.ID<0) then
exit; // we need a valid record and its ID
if not RetrieveBlob(TSQLSampleRecord,aRecord.ID,'Wave',aData) then
exit; // impossible to retrieve the Data BLOB field
setLength(Values,Length(aData) div 4);
Move(pointer(aData)^,Values[0],Length(aData));
//aResp := JSONEncodeResult([SynCommons.BinToHex(aData)]);
aResp:=JSONEncodeArray(Values,3);
// idem: aResp := JSONEncode(['result',BinToHex(aRecord.fData)],TempMemoryStream);
result := 200; // success
end;
supported the values is [116.40,112.54]
the right result JSONArray is [1.16E2,1.13E2] ,now the result is [2.18E14,0].why?
JSONEncodeDouble(const Values: array of double;decimals: integer;..
decimals only can define how many digital number in string.
i think the formatstring: like '#.00' or '#.##' is very used in JSONEncodeDouble.
if we use decimals. sometimes the Value will be Scientific format.In http webpages it's not wanted.
Convert from hex to javascript float?
I don't think that's possible, because javascript don't know about singe/double/extended which are x87 FPU values.In this case, you must transmit your data as JSON.
ok.i will solve it by Server side, i can define onenew function of returning Json string for my Array of single Data.
thanks a lot
But if your purpose is to store an array of single/double just for Delphi applications, you don't need to use hex encoding, you can transmit raw binary data with such blob fields, therefore spare some bandwidth.
Then map the array with TRawByteString using SetString(aBlob,) and SetLength(Array,)+move() as I've shown you.
sir:
i mean how to get Data in WEB pages. for DataasHex function have returned with Hexstirng data. i googled it more,haven't get good method. do you have some about it.
our httpServer have added new functions ,like dataasHex ,in Ajaxrequest, we can get Hexstr, now i don't know how to convert. thanks a lot.
when write some chinese words in SypPDF ,it's wome wong codes.
This sound good. So I'm waiting your demo until the Administrator won't release an official big demo
Thanks
study together
it's cross domain problem, i am googling for it, thanks a lot
if my Datetime is 2010-07-22 18:44:52:532,in fact it's double
the Int32ToUft8() only can get Int value,
how to transfer,thanks a lot
Sir, how to find Message based on time like this
Rec := TSQLSampleRecord.Create(Database,'Name="%"',[StringToUTF8(NameEdit.Text)]);
and in Sqlite3, can you write one Query Options based one time Colfield ,i haven't found any files about this.
like this,One is statand SQL option, another is delphi query option
select * from Samplerecord where time....
thanks a lot,
in loacal pc, when i input "http://192.168.1.100/test.hml" which uses Ajax request. i can get some data. but when i input the same Address in LAN pc, the IE error prompts "refuse visit". perhaps it's in the diffrent domain. tell me why or how to config OS.
....//ajax request code
var oXmlHttp=zXmlHttp.createRequest(); //one ajax class
var url='http://192.168.1.100:8080/root/samplerecord/1";
var returnLen;
oXmlHttp.open("get",url,true);
....
oXmlHttp.open("get",url,true);
IE Error shows
The highlight line can't open or refuse visit.
wait for days ,i can write one example about what i know for this Framework
thanks your hard work,it's successful
Problem about html comes not from SynPdf here...
i think the problem is from synpdf , or Thtmlview code.
for i test the Example5 ,i write some chinese words in the Text, it also shows wrong fonts.
you can install asian fonts in you pc, and then test it
test html codes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>无标题文档</title>
</head>
<body>
<strong><font size="+5">20100716测试中文字体,中国北京</font></strong><br>
Test chinese Font
</body>
</html>
longge007 wrote:Exception class EAccessViolation with message 'Access violation at address 004C021A
Which line source code is it? Hexa address are pointless, because it depends on your compiler and libraries...
I suspect you didn't get all modifications from our source code repository, but modified the code by hand, according to my comment in my previous post, which is not enough.
yeah, it's right, i only change some.
now ,it can create PDF file ,but can't show chinese fonts, all are Error code.
They must be an error with chinese code page and such... I'll check.
i have sent you an Email ,please Check it.
it seems that the content of fDoc.FTrueTypeFonts list is different from which in my windows fonts directory.
my computer system is windows XP with service pack 2
PDF uses Embeded font,mostly don't support Chinese Font. In order to show Chinese Fonts ,it's necessary to translate it.
can't SameText()
so FontIndex always equal -1, then Error occurs.
setFont times New Roman.