#1 Re: Source Code repository » SynCommons: TDynArray and Record compare/load/save using fast RTTI » 2011-03-18 17:37:36

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;

#2 mORMot 1 » Proposed new overloaded CreateSQLIndex method » 2010-12-01 16:37:53

JonG
Replies: 1
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.  smile 
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.

#3 Re: mORMot 1 » Will the SQLite3UI units set become TMS-independent? » 2010-12-01 16:21:53

migajek wrote:

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 something wink

I've changed the code to follow the correct pattern.

Also, the demo shows TSQLTableToGrid as well now smile

I am interested in looking at that demo.  Where is it available?

Thanks!

#4 mORMot 1 » retrieving multiple records » 2010-11-18 05:45:37

JonG
Replies: 1
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.

#5 Re: mORMot 1 » SQLite3 Framework Indexes » 2010-11-15 13:00:30

ab wrote:
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

#6 Re: mORMot 1 » SQLite3 Framework Indexes » 2010-11-15 02:46:14

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!

#7 mORMot 1 » SQLite3 Framework Indexes » 2010-11-12 14:22:39

JonG
Replies: 7

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

Board footer

Powered by FluxBB