You are not logged in.
Pages: 1
I love the new TDynArray functionality!
Will TDynArray handle records inside of records?
type
TName = Record
First : String;
Last : String;
end;
TAddress = Record
Street : String;
Suite : String;
City : String;
State : String;
Zip : String;
end;
TPerson = Record
Name : TName;
Address : TAddress;
end;
TPersonDynArray = array of TPerson;
function TSQLRestServerDB.CreateSQLIndex(Table: TSQLRecordClass;
const IndexName : RawUTF8;
const FieldNames: array of Const;
Unique: boolean): boolean;
var SQL, SQLTableName: RawUTF8;
TableIndex: integer;
FieldNamesStr : RawUTF8;
i : integer;
sr : RawUTF8;
IdxNameStr : RawUTF8;
BuildIdxNameStr : Boolean;
begin
Result := False;
TableIndex := Model.GetTableIndex(Table);
if (TableIndex<0) or
((fStaticData<>nil) and (fStaticData[TableIndex]<>nil)) then
exit; // invalid Table or in Static data (index not needed)
IdxNameStr := IndexName;
BuildIdxNameStr := (IdxNameStr = '');
for I := low(FieldNames) to High(FieldNames) do begin
VarRecToUTF8(FieldNames[i],sr);
if sr = '' then Exit;
if (Table.FieldIndex(sr)<0) then
Raise Exception('Invalid Fieldname: "'+sr+'"')
else begin
FieldNamesStr := FieldNamesStr+', "'+sr+'"';
if BuildIdxNameStr then
IdxNameStr := IdxNameStr + '_' + sr;
end;
end;
if FieldNamesStr = '' then
Exit;
SQLTableName := Table.SQLTableName;
if BuildIdxNameStr then begin
System.Delete(IdxNameStr,1,1);
IdxNameStr := SQLTableName+'IdxBy'+IdxNameStr;
end;
System.Delete(FieldNamesStr,1,2);
if Unique then
SQL := 'UNIQUE ' else
SQL := '';
SQL := FormatUTF8('CREATE %INDEX IF NOT EXISTS % ON %(%);',
[SQL,IdxNameStr,SQLTableName,FieldNamesStr]);
result := EngineExecuteAll(SQL);
end;
I borrowed heavily from the existing method of the same name.
Advantages: 1. This method allows indexes to be made up of more than one field. 2. Allows you to specify (or not) the index name.
Hi,
indeed that was a bit unclear - since the demo 02 used the server directly. Unfortunately I'm the kind of guy who looks at the examples first, than refers to the documentations when needs to clarify somethingI've changed the code to follow the correct pattern.
Also, the demo shows TSQLTableToGrid as well now
I am interested in looking at that demo. Where is it available?
Thanks!
procedure TForm1.LoadPersonList;
var
PersonRec : TSQLPersonRecord;
begin
PersonRec:=TSQLPersonRecord.Create(Database,'Name>""',[]);
Try
if PersonRec.ID = 0 then
Exit;
Repeat
ListBox1.Items.Append(UTF8ToString(PersonRec.Name));
until not PersonRec.FillOne;
Finally
PersonRec.Free;
End;
end;
This code is not working. I know there are multiple records in the table but only the first record comes up.
What am I doing wrong? :-)
Many thanks.
JonG wrote:I had seen EngineExecuteAll but didn't see it in the hierachy of TSQLRest. Later I saw that the sample code typecasts TSQLRest as TSQLRestServerDB which does have the EngineExecuteAll function.
Indeed. The framework is therefore not bounded to the SQLite engine.
In the upcoming future, we'll add Oracle+MSSQL+MySQL+Firebird support as database engine layer for the framework.TSQLRestServerDB is the embedded SQLite3 engine. You don't have any server instance, but direct access to the database from your app.
Later on, you can change this embedded behavior into a Client/Server approach, just by changing the class type.
That as well as strong typecasting interface with Delphi is why I selected SQLite and SQLFW for my first foray into SQL. Thanks for the great work!
Best wishes,
- Jon
I had seen EngineExecuteAll but didn't see it in the hierachy of TSQLRest. Later I saw that the sample code typecasts TSQLRest as TSQLRestServerDB which does have the EngineExecuteAll function.
Thanks!
Please forgive my ignorance.
If I am using embedded SQLite, how can I execute SQL statements? I want to define some indexes and I don't see the framework way to do it.
Kind regards,
- jon
Pages: 1