You are not logged in.
try modernize code ClientRest.ExecuteList([], s) with FormatUTF8 (executelist need - have several commands inner join)
old part code (work fine):
Result := Result + 'strftime("%Y", InputDate) = ' + cbbCurrentYear.Value.QuotedStringif change old part to new part code not work:
Result := Result + FormatUTF8('strftime("%Y", InputDate) = ?', [], [cbbCurrentYear.Value]);if result i see: ' strftime("Y", InputDate) = ?'. any idea how format sql with expression?
ab, sorry may be i slowpoke, but i dont understand how can i realize hidden columns by using TSQLTable.SetFieldLengthMean().
if write something like this:
SetLength(len, tbl_patients.FieldCount - 1);
for i := 0 to tbl_patients.FieldCount - 1 do len[i] := tbl_patients.FieldLengthMean(i);
len[colAproove] := 0;
len[colDecline] := 0;
tbl_patients.SetFieldLengthMean(len);
with TSQLTableToGrid.Create(dgList, tbl_Patients, ClientRest) do begin
ShowHint := False;
OnValueText := OnValueTextTablePatients;
OnDrawCellBackground := OnDrawCellBackgroundPatients;
Resize(nil);
...
end;it does not work, since resize run after this code, and all columns recalculated
P.S. i try use TSQLTableToGrid procedure, but procedure has different format and apply for all column(((
procedure TSQLTable.SetFieldLengthMean(const Lengths: array of cardinal);
...
procedure TSQLTableToGrid.SetFieldLengthMean(const Lengths: RawUTF8; aMarkAllowed: boolean);
... TSQLFieldType = (
sftUnknown, sftAnsiText, sftUTF8Text, sftEnumerate, sftSet,
sftInteger, sftID, sftRecord, sftBoolean,
sftFloat, sftDateTime, sftTimeLog, sftCurrency, sftObject,
{$ifndef NOVARIANTS}
sftVariant,
{$endif}
sftBlob, sftBlobDynArray, sftBlobCustom, sftUTF8Custom, sftMany,
sftModTime, sftCreateTime, sftTID, sftRecordVersion, sftHidden); //<=== add sftHidden, and other constants toofunction TSQLTable.CalculateFieldLengthMean(var aResult: TIntegerDynArray;
FromDisplay: boolean=false): integer;
...
case fFieldType[F].ContentType of
...
sftHidden: aResult[F]:=0;
...
for F := 0 to FieldCount-1 do begin
if aResult[F] = 0 then Continue;
...AB, can you add sftHidden to framework?
quick fix
procedure TSQLTable.DeleteColumnValues(Field: integer);
var i: integer;
U: PPUTF8Char;
begin
if cardinal(Field)>=cardinal(FieldCount) then
exit; // out of range
U := @fResults[Field+FieldCount]; // U^ = column UTF-8 content for this field
for i := 1 to fRowCount do begin
if U^ <> nil then U^[0] := #0; // just void UTF-8 content text //ADD if U^ <> nil then
inc(U,FieldCount);
end;
end;yes it works - column hide but have no data and no color((( Need only hide column without erase data
i think add sftNotVisible best solution
I tried this function, but it's not what me need, especially as a function of the error if I specify the column in which the row 5 no data (for example, an empty string) function returns an error. (if all the rows have the data all works), though I do not understand why it can be necessary, because you can simply specify the column in the sql command.
I do not need to display an empty column without the data I need to hide a column.
i have wide monitor, but many users not have. User dont need last 2 column - color show approve or decline this record.
of course table show in auto resize
with TSQLTableToGrid.Create(dgList, tbl_Patients, ClientRest) do begin
ShowHint := False;
OnValueText := OnValueTextTablePatients;
OnDrawCellBackground := OnDrawCellBackgroundPatients;
Resize(nil);
...
end;before
after
function TSQLTable.CalculateFieldLengthMean(var aResult: TIntegerDynArray;
FromDisplay: boolean=false): integer;
...
for R := 1 to fRowCount do // sum all lengths by field
for F := 0 to FieldCount-1 do begin
case fFieldType[F].ContentType of
...
sftUnknown: aResult[F]:=0; // I ADD THIS TO WORK HIDE COLUMN
...
for F := 0 to FieldCount-1 do begin
if aResult[F] = 0 then Continue; // IF 0 HIDE COLUMN, SOME TIMES NEED HIDE COLUMN
n := cardinal(aResult[F]) div Tot; // Mean = total/count
if n=0 then n := 1; // none should be 0
aResult[F] := n;
inc(result,n); // fast calculate mean sum
end;i hide column to save space in grid, approvedate - green color in table, declinedate - red color in table, not need show 2 column
tbl_patients := ClientRest.ExecuteList([], s);
tbl_patients.SetFieldType('approvedate',sftUnknown);
tbl_patients.SetFieldType('declinedate',sftUnknown);or may be add new type sftNotVisible?
creating the WHERE clause with the overloaded FormatUTF8() allowing both Args and Bounds parameters.
thanks i change my code
...'where ' + FormatUTF8('r.mo = ? AND r.Created BETWEEN ? AND ?', [], [mo_id, TimeLogFromDateTime(db), TimeLogFromDateTime(de)]);Try to use TSQLRest.MultiFieldValues
but how create join with 4 tables?
function MultiFieldValues(Table: TSQLRecordClass; const FieldNames: RawUTF8;
const WhereClauseFormat: RawUTF8; const BoundsSQLWhere: array of const): TSQLTableJSON; overload;if put inner join in FieldNames he placed before FROM, if put in WhereClauseFormat he placed after WHERE
TTimeLog fields are stored as Integer SQLite3 values, so they should work.
it works, sorry gramma misstake BETWEEN not BEETWEN.
' AND (r.Created BETWEEN ? AND ?)');
t := ClientRest.ExecuteFmt(s,[],[TimeLogFromDateTime(db),TimeLogFromDateTime(de)]);yes but ExecuteFmt return boolean not table(((.
it would be wonderful to have a execute format returned table
i not using external DB.
server
with TSQLite3HttpService.Create do
try
ServicesRun;
finally
Free;
end;client
Model := CreateModel;
ReadConfig;
ClientRest := TSQLHttpClient.Create(ip, port, Model);
ClientRest.ForceBlobTransfert := True;
if not ClientRest.ServerTimeStampSynchronize then Result := False;sql exec
s :=
'select ls.TradeNmR, ls.InnR, ls.DosageR, ls.PackQn, ls.EAN, r.Series, r.MnfPrice, r.PrcPrice, ' +
'r.TotDrugQn, v.VendorNm, z.Name, r.RekvType, r.RekvNum, r.RekvDate ' +
'from Recs r ' +
'inner join RZLS ls on r.DrugID = ls.DrugID ' +
'inner join RZVendor v on r.VendorID = v.VendorID ' +
'inner join Zakupka z on r.ZakupkaID = z.ID ' +
'where r.mo = ' + mo_id.ToString +
// ' AND r.Created BEETWEN ' + IntToStr(TimeLogFromDateTime(db)) + ' AND ' + IntToStr(TimeLogFromDateTime(de));
' AND r.Created >= ' + IntToStr(TimeLogFromDateTime(db)) + ' AND r.Created <= ' + IntToStr(TimeLogFromDateTime(de));
t := ClientRest.ExecuteList([], s);BETWEEN not work only in TTimeLog fields, with others work pretty fine
dont understand why this work
...' AND Created >= ' + IntToStr(TimeLogFromDateTime(db)) + ' AND Created <= ' + IntToStr(TimeLogFromDateTime(de));but this dont work
...' AND Created BEETWEN ' + IntToStr(TimeLogFromDateTime(db)) + ' AND ' + IntToStr(TimeLogFromDateTime(de));create pas, add constant with u path and add on client and server app or save in db in special options table paths and others sys info
to warleyalex,
рш, сan you put your sample demo here (better if ab add it to ThirdPartyDemos)?
to warleyalex:
see sample 26 - RESTful ORM
RESTServerClass.pas
procedure TNoteServer.Blob(Ctxt: TSQLRestServerURIContext);
i change in source from
procedure TSQLTableToGrid.DrawGridMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
...
if ARow=0 then
if (ssCtrl in Shift) or (Button<>mbLeft) then begin
// Ctrl or right button pressed -> display first row as hint
ShowHintString(U2S(Table.Get(ARow,ACol)),ACol,ARow,4000);to
SQLTableToGrid.OnHintText := OnListText;
procedure TSQLTableToGrid.DrawGridMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
...
if ARow=0 then
if (ssCtrl in Shift) or (Button<>mbLeft) then begin
// Ctrl or right button pressed -> display first row as hint
if Assigned(OnHintText) and OnHintText(Table,ACol,ARow,Hint) then
ShowHintString(Hint,ACol,ARow,4000)
else
ShowHintString(U2S(Table.Get(ARow,ACol)),ACol,ARow,4000);its work and view russian name column, but first i see english column name before draw russian column name. How draw text without this bug?
very simple replace text in header drawgirid use function
fieldText: array [0..10] of string = (
'№',
'№ БЛ',
'Выдан',
'Фамилия',
'Имя',
'Отчество',
'Д/р',
'Место работы',
'пред БЛ',
'след БЛ',
'#');
...
SQLTableToGrid.OnValueText := OnListText;
...
function TfrmMain.OnListText(Sender: TSQLTable; FieldIndex, RowIndex: Integer; var Text: string): boolean;
begin
if RowIndex = 0 then begin
Text := fieldText[FieldIndex];
Result := True;
end
else
Result := False;
end;but how change hint (sample right click on header), i dont find this function, and no option to disable
big big thanks for sample!
before it was, but still does not work.
aClient.CallBackGet('blob', [], response, TSQLNoteFile);
write(response);
aClient.CallBackPut('blob', jpgRaw, response, TSQLNoteFile);dont understand why, please try run this client with sample 26 server.
problem how "call root/notefile/blob"
i run server from 26 sample and if i run client i get "<h1>Bad Request (Invalid Hostname)</h1>"
/// minimal REST client for a list of Persons from RESTserver.exe
program RESTclient;
{$APPTYPE CONSOLE}
uses
SynCommons, // framework core
mORMot, // RESTful server & ORM
mORMotHttpClient, // HTTP client to a mORMot RESTful server
SynGdiPlus,
RESTData; // data model unit, shared between server and client
var aModel: TSQLModel;
aClient: TSQLHttpClient;
aRootURI, response: RawUTF8;
jpg: TJPEGImage;
jpgRaw: RawByteString;
begin
Gdip := TGDIPlusFull.Create;
aModel := DataModel(aRootURI);
try
aClient := TSQLHttpClientWinHTTP.Create('localhost','888',aModel);
jpg := TJPEGImage.Create;
jpg.LoadFromFile('d:\scans\1.jpg');
SaveAsRawByteString(jpg, jpgRaw, gptJPG);
aClient.CallBackGet('root/notefile/blob', [], response, TSQLNoteFile);
write(response);
aClient.CallBackPut('root/notefile/blob', jpgRaw, response, TSQLNoteFile);
write(response);
write(#10'Press [Enter] to quit');
readln;
finally
aModel.Free;
end;
Gdip.Free;
end.thanks, i see sample, but dont understand how it works. all samples have client and server files, but 26 - RESTful ORM\RESTServerClass.pas have only server side
hi, i use sample 10 - Background Http service.
is it possible use client side procedure to save the image from blob to server folder?
How to connect to MySQL Server via ZEOS or UNIDAC with Mormot
http://synopse.info/forum/viewtopic.php?id=1547
i see many question how connect to different base, ab may be better create sample for connect to all base and put it into sample folder with source?
ab's answer: there are so many combination of DB / Library possible, that we could not be exhaustive. But any valuable input will be added to the documentation.
any news about distinct?
need to write repetitive code, sample
procedure Fill_combobox_data(r: TSQLRecord; s: TStrings; field: string);
begin
s.Clear;
r.CreateAndFillPrepare(Database, '');
try
while r.FillOne do s.Add(r.RecordProps.Fields.ByRawUTF8Name(field).GetValue(r, False));
finally
r.Free;
end;
end;if me need add distinct need write additional procedure
procedure Fill_distinct_combobox_data(r: TSQLRecord; s: TStrings; field: string);
var
t: TSQLTable;
begin
s.Clear;
t := Database.List([r.RecordClass], 'distinct trim(' + field + ') as ' + field, '');
if t = nil then Exit;
t.OwnerMustFree := False;
r.FillPrepare(t);
try
while r.FillOne do s.Add(r.RecordProps.Fields.ByRawUTF8Name(field).GetValue(r, False));
finally
r.Free;
t.Free;
end;
end;what is currently the best option for the use of a distinct in framework?
I read the documentation and can not understand how to do the following in Example 04:
1) change the name, password and the right standard account (Database.SetUser ('User', 'synopse'))
2) add a new account
Maybe there is a simple example of management accounts?
Sample 04
Form1.Database := TSQLHttpClient.Create(Server,'8080',Form1.Model);
TSQLHttpClient(Form1.Database).SetUser('User','synopse');if run in Delphi we see message Project Project04Client.exe raised exception class EWinHTTP with message 'Unable to connect to localhost:8080 - server may be down or unavailable'.
i try use terminate on except but nothing happends
Form1.Database := TSQLHttpClient.Create(Server,'8080',Form1.Model);
try
TSQLHttpClient(Form1.Database).SetUser('User','synopse');
except
Application.Terminate;
end;How to verify that the server is down?
As a workaround (If your businnes logic allow) - use commit on every 512 record. In all case this is faster compared to long transaction.
i try but no effect
We have just removed MAX_SQLLOCKS constant non-sense (replaced by two dynamic arrays).
Should work as you expected now.:)
thanks, now work pretty well
TSQLProduct = class(TSQLRecord)
private
...
fPreview: TByteDynArray;
published
...
property preview: TByteDynArray read fPreview write fPreview;
procedure FillPreview;
var
prd, p: TSQLProduct;
ids: TIntegerDynArray;
picBin: TByteDynArray;
ms: TMemoryStream;
begin
p := TSQLProduct.CreateAndFillPrepare(Database, '');
if Database.TransactionBegin(TSQLProduct) then
try
Database.BatchStart(TSQLProduct);
while p.FillOne do begin
if p.preview <> nil then Continue;
prd := TSQLProduct.Create(Database, p.ID, True);
try
ms := TMemoryStream.Create;
try
ms.LoadFromFile(pathDir + p.fPath);
SetLength(picBin, ms.Size);
Move(ms.Memory^, picBin[0], ms.Size);
prd.preview := picBin;
finally
ms.Free;
end;
Database.BatchUpdate(prd);
finally
FreeAndNil(prd);
end;
end;
Database.BatchSend(ids);
Database.Commit;
except
Database.RollBack;
end;
FreeAndNil(p);
end;directory contains about 3000 jpg, but update only 512, i found in source MAX_SQLLOCKS constant and change to 1024 and re run test, 1024 record updated
/// maximum number of the locked record in a Table (used in TSQLLocks)
// - code is somewhat faster and easier with a fixed cache size
// - 512 seems big enough on practice
MAX_SQLLOCKS = 1024;
how to update all records regardless of the constants MAX_SQLLOCKS?
global atom bug sample and solution (AtomCleaner)
http://screenup.org/habr/atom_projects.zip
Misuse of atoms and elusive bug in the VCL
http://habrahabr.ru/post/217189/
http://rouse.drkb.ru/components.php#fwzip
open source alternative with plenty of opportunities: large files, few need memory, password protect archive and unarchive, ppmd
yes at the moment, in the six months were no complaints.
but I think it is not the best option, because know only superficially framework
problem see on last 3 column, he have data not in each row and standart algoritm compress column. fix normalize size column
i use drawgrid autosize column width, but it work terrible, maybe I do not see how you can control the functions they.
small rewrite source mormot.pas from (https://www.dropbox.com/s/iwf6npz0lufle … column.JPG)
for R := 1 to RowCount do // sum all lengths by field
for F := 0 to FieldCount-1 do begin
case fFieldType[F].ContentType of
sftInteger, sftBlob, sftBlobCustom, sftUTF8Custom, sftRecord,
sftID, sftSet, sftCurrency:
inc(aResult[F],8);
else inc(aResult[F],Utf8FirstLineToUnicodeLength(U^));
end;
inc(U); // points to next value
end;to
var nullfield: integer;
for R := 1 to RowCount do // sum all lengths by field
for F := 0 to FieldCount-1 do begin
case fFieldType[F].ContentType of
sftDateTime: inc(aResult[F],8)
else begin
nullfield := Utf8FirstLineToUnicodeLength(U^);
if nullfield = 0 then nullfield := 8;
inc(aResult[F],nullfield + 1);
end;
end;
inc(U); // points to next value
end;and see more better i think (https://www.dropbox.com/s/xmnveo759oskn … column.JPG)
If I understand well, the difference between computers is also the proxy definition?
AFAIK TWinINet.Get() will transparently use the system (aka Internet Explorer) proxy settings.
no, all computers have some proxy. i know about proxy setting and they are the same everywhere.
I do not understand why HttpGet not working on 4 computers.
In my home pc on win 8.1 work fine without problem.
i dont understand, try all variant but no one not work.
ShowMessage(HttpGet('koscrb.dzo-kostroma.ru', '80', 'index.php?page_id=1'));
ShowMessage(TWinHTTP.Get('koscrb.dzo-kostroma.ru/index.php?page_id=1'));
ShowMessage(TWinINet.Get('koscrb.dzo-kostroma.ru/index.php?page_id=1'));my program use chromium and in chromium this link koscrb.dzo-kostroma.ru/index.php?page_id=1 work fine, no problem connection and in any browser on this pc (ie, chrome) link also works well.
I'd like to use mormot HttpGet, very simple command, but this bug puzzles me.
i install last version OverbyteIcs, try use and this code works
With HttpCli1 do begin
URL := 'http://koscrb.dzo-kostroma.ru/index.php?page_id=1';
Proxy := '10.44.1.163';
ProxyPort := '3128';
RequestVer := '1.1';
RcvdStream := TMemoryStream.Create;
try
Get;
except
RcvdStream.Free;
Exit;
end;
RcvdStream.Seek(0,0);
Memo1.Lines.LoadFromStream(RcvdStream);
RcvdStream.Free;
end;hi, i again get problem, in my work on win xp, win 7 work fine, no problem.
but on infomat pc (win 7 maximal) httpget dont work.
all computers work in same proxy. code for test:
ShowMessage(HttpGet('www.ecb.europa.eu', '80', '/stats/eurofxref/eurofxref-daily.xml'));in module syncrtsock i place message for test, after message size sin = 16, long wait and then message connect failed and empty message.
function CallServer(const Server, Port: RawByteString; doBind: boolean; aLayer: TCrtSocketLayer): TSocket;
...
showmessage('try connect');
showmessage('size sin = ' + IntToStr(SizeOfVarSin(Sin))); // size sin = 16
if Connect(result,Sin)<>0 then begin
CloseSocket(result);
showmessage('connect failed');i solve my problem, but may be add HttpGet TimeOut parameter?
function HttpGet(const server, port: AnsiString; const url: RawByteString): RawByteString;
var Http: THttpClientSocket;
begin
result := '';
Http := OpenHttp(server,port); <--- next see OpenHttp declaration
if Http<>nil then
try
if Http.Get(url)=200 then
result := Http.Content;
finally
Http.Free;
end;
end;
function OpenHttp(const aServer, aPort: AnsiString): THttpClientSocket;
begin
try
result := THttpClientSocket.Open(aServer,aPort); <--- next see Open declaration
except
on ECrtSocket do
result := nil;
end;
end;
function Open(const aServer, aPort: AnsiString): TCrtSocket;
begin
try
result := TCrtSocket.Open(aServer,aPort);
except
on ECrtSocket do
result := nil;
end;
end;
constructor Open(const aServer, aPort: AnsiString; aLayer: TCrtSocketLayer=cslTCP; aTimeOut: cardinal=5000); <--- bingo find aTimeOut parameters and set 15000 and work fine.hi again, it work fine for normal sites, but if i load slow sites i raised exception class ECrtSocket with message 'SockRecvLn 1'.
site slow load in browser 6-10 second, but load!
http://kobsme.dzo-kostroma.ru/index.php?page_id=3
my project - free infomat for medical institutions, please help how load data from slow site
may be stick this topic?
maybe other user too post videos in this topic
dont see drop table method, current realization
Database.EngineExecute('delete from Products');
VacuumBase;
procedure VacuumBase;
begin
with TSQLRestClientDB(Database).Server do begin
DB.Lock('');
try
EngineExecuteAll('VACUUM');
finally
DB.UnLock;
end;
end;
end;but i think drop table and recreate table more faster?
I've just added a new optional CustomFields parameter to TSQLRestClientURI.BatchUpdate() and BatchAdd() methods.
See http://synopse.info/fossil/info/56f240ed05It would be able to do directly what you expect to do.
great, but I do not understand how to use this opportunity
my current realization
TSQLProduct = class(TSQLRecord)
private
fCategory: Integer;
fPath, fName, fWeight: string;
fPicture: TByteDynArray;
published
property category: Integer read fCategory write fCategory;
property path: string read fPath write fPath;
property name: string read fArtikul write fArtikul;
property weight: string read fWeight write fWeight;
property picture: TByteDynArray read fPicture write fPicture;
end;
...
if Database.TransactionBegin(TSQLProduct) then
try
Database.BatchStart(TSQLProduct);
cat_id := 1;
d := SetPathSep([TDirectory.GetCurrentDirectory, 'zl', 'valuables']);
for directory in TDirectory.GetDirectories(d, TSearchOption.soTopDirectoryOnly, nil) do begin
for f in TDirectory.GetFiles(Directory) do begin
prd := TSQLProduct.Create;
try
with prd do begin
category := cat_id;
path := ExtractRelativePath(d, f);
GetInfoFromFileName;
name := sl[0];
weight := sl[1];
ms := TMemoryStream.Create;
try
ms.LoadFromFile(f);
SetLength(picBin, ms.Size);
Move(ms.Memory^, picBin[0], ms.Size);
finally
ms.Free;
end;
picture := picBin;
Database.BatchAdd(prd, True);
end;
finally
FreeAndNil(prd);
end;
end;
Inc(cat_id);
end;
Database.BatchSend(ids);
Database.Commit;
except
Database.RollBack;
end;I deliberately removed checks for the existence of records, as each time the database will be clear.
after approv base will not be changing.
thanks for reply, i find good sample with TByteDynArray: http://synopse.info/forum/viewtopic.php?pid=3832#p3832
in sample i trying set DataBase.ForceBlobTransfert := True; but nothing happend
how correct allow blob batch mode?
Updating BLOB fields should already be available, if you retrieve the fields using a FillPrepare (since updated fields will follow the one retrieved with the FillPrepare).
i try use this code but it too not work
if Database.TransactionBegin(TSQLProduct) then
try
Database.BatchStart(TSQLProduct);
prd := TSQLProduct.Create;
try
prdtable := Database.ExecuteList([TSQLProduct], 'select * from product');
prd.FillPrepare(prdtable);
while prd.FillOne do
with prd do begin
pic := '';
g := TPicture.Create;
g.LoadFromFile(prd.pathtofile);
SaveAsRawByteString(g, pic, gptJPG);
picture := pic;
Database.BatchUpdate(prd);
end;
finally
FreeAndNil(prd);
end;
Database.BatchSend(ids);
Database.Commit;
except
Database.RollBack;
end;i too try add images in batch mode, but blob field is null
how fast add many records with one image in blob?
i write simple sample with 1 record, but me need add about 2000-4000 record
https://www.dropbox.com/s/5j07635nwt387 … om_base.7z
indeed it would be great to already have some videos, but unfortunately there is no source projects.
It would be possible to add them to the branch samples repository.
Yes, I can share this project, but I don't have any repository... send by email?
thanks, may be post source on github?
I think it very good idea create samples repository or Sticky topic with samples.
Few old demo posted on this forum:
Drives by gclaxton
http://synopse.info/forum/viewtopic.php?id=329
Record generator tool by migajek
http://synopse.info/forum/viewtopic.php?id=350
Demo application (users-customer-task-roles) by migajek
http://synopse.info/forum/viewtopic.php?id=164
LiveBindingsFireMonkey by AntonE
http://synopse.info/forum/viewtopic.php?id=1115
i have some problem. (XE2 and XE3 on latest source)
may be you write small sample of httpget:
1) get xml
2) get jpeg
if try assign png runtime from file or pngimagecollection i see png
too dont understand why enable Gdip.RegisterPictures; dont show png