#101 Re: mORMot 1 » boolean data type created as int(11) in MySQL » 2015-05-19 08:05:30

ab wrote:

Create the table by hand, before the ORM tries to create it.

by hand you mean executing a custom SQL "create table..."?

#102 mORMot 1 » index creation in the mORMot » 2015-05-19 08:03:04

cypriotcalm
Replies: 4

Hi ab,

I have also several questions about the index creation.

1. How can I enable or disable the automatic index creation? I mean the indexes which look like INDEX7CB68FFE350C6FF1(...)
2. How can I check through the ORM whether an index already exists?
3. How can I create my own indexes through the ORM?

Thank you for your answers!

#103 mORMot 1 » boolean data type created as int(11) in MySQL » 2015-05-19 07:52:33

cypriotcalm
Replies: 4

Hi ab,

if I define a custom SQL-class inherited from TSQLRecord with a boolean field and let the ORM create the corresponding table in a MySQL database, the boolean field is created as int(11) and not as tinyint(1) which is a type for the boolean-values in MySQL. After the table creation I have a problem to read this field in delphi. I get an error something like "... this is not a boolean value type..."

How could I solve this problem through the ORM?

Thanks!

#104 mORMot 1 » interface inheritance at RegisterInterfaces internal error L2111 » 2015-05-19 07:10:52

cypriotcalm
Replies: 31

Hi ab,

i have the following problem. I have the source code:

  // interface I
  IPhoMessartQuery = interface(ICQRSQuery)
  ['{CCFB5FAA-FFA2-437A-849C-E7F5A57763D6}']
    function SelectByName(const AName: String): TCQRSResult;
    function Get(out AAggregate: TPhoMessart): TCQRSResult;
    function GetAll(out AAggregates: TPhoMessartObjArray): TCQRSResult;
    function GetNext(out AAggregate: TPhoMessart): TCQRSResult;
    function GetCount: Integer;
  end;

  // interface II
  IPhoMessartCommand = interface(IPhoMessartQuery)
  ['{EF721955-203E-4A3E-9FD2-B83A2939669E}']
    function Add(const AAggregate: TPhoMessart): TCQRSResult;
    function Update(const AUpdatedAggregate: TPhoMessart): TCQRSResult;
    function Delete: TCQRSResult;
    function DeleteAll: TCQRSResult;
    function Commit: TCQRSResult;
    function Rollback: TCQRSResult;
  end;

initialization
  TInterfaceFactory.RegisterInterfaces([TypeInfo(IPhoMessartQuery), TypeInfo(IPhoMessartCommand)]);

Unfortunately I can't compile it and I get an internal error L2111.
I have tried to close the project and restart the IDE in order to clear the unit cache. It didn't help.

But if I change my code in a way that the interface II inherits from ICQRSQuery, i.e.

  // interface II
  IPhoMessartCommand = interface(ICQRSQuery)
  ['{EF721955-203E-4A3E-9FD2-B83A2939669E}']
   ...
  end;

I can compile the code without problems.

Do you have an idea how I can get rid of the internal error without the changing the code?

Thank you!

#105 mORMot 1 » TSQLRecordClass with different tables/table names » 2015-04-27 11:29:27

cypriotcalm
Replies: 1

I have a bit dynamic database model. Some tables will be created only then if some data was measured and has to be saved into the database. These tables get unique names which are each time different. The table structure is always the same, only the table names differs.

I would like to map these tables with mORMot because I don't want to use SQL directly.

How could I solve this problem with mORMot? Is there a possibility to use the same SQLRecordClass but each time with different table names?

I hope, you understand what my problem is and could help me!

Thank you in advance!

#107 mORMot 1 » create table without ID » 2015-04-23 12:07:55

cypriotcalm
Replies: 2

Hi!

I have a database table with only two columns, they are a compound key, but I don't have any ID column as a primary key. If I execute CreateMissingTables I get an exception EMySQLNativeException [AnyDAC][Phys][MySQL] "Unknown column ID in field list".

  VirtualTableExternalRegister(FSQLModel, TMyDatabaseTableExt, FSQLConnectionProperties, 'MyDatabaseTable');
  FRestServer.CreateMissingTables();  

How can I handle this? Thank you for your help!

#108 Re: mORMot 1 » read/write MariaDB dynamic columns binary json » 2015-04-01 07:18:10

:-) I see... I would like to create a patch but I am not sure if I can do this and I don't know where and how to start because I have never coded for the open source projects!? :-(

#109 Re: mORMot 1 » read/write MariaDB dynamic columns binary json » 2015-04-01 06:17:31

ab wrote:

This is not yet supported.

In fact, this is pretty close to the JSONB format of latest PostgreSQL.
But it sounds like if the COLUMN_CREATE feature is much more limited than JSONB, e.g. it does not support arrays.
See https://mariadb.com/kb/en/mariadb/dynamic-columns/
So IMHO I do not see any benefit of using it, in respect to a mORMot variant field, stored as text, and handled as TDocVariant in our framework.

What I would like to do is to execute a SELECT-Satetment on a JSON-column in an SQL browser after I have saved some JSON-data. And if I save this data in the "MariaDB" compatible format (now only throug an INSERT using the command COLUMN_CREATE), I can execute a SELECT (see below) and I'll get in my result (ID, Firstname, Lastname) although the column `Data` is saved as JSON or rather JSONB.

SELECT `ID`, COLUMN_GET(`Data`, 'Firstname' AS CHAR) AS Firstname, COLUMN_GET(`Data`, 'Lastname' AS CHAR) AS Lastname FROM `person`;

I hope, you understand what I mean ;-)

#110 mORMot 1 » read/write MariaDB dynamic columns binary json » 2015-03-27 15:16:44

cypriotcalm
Replies: 4

Hi!

Does mORMot support the MariaDB dynamic columns?

I mean, if I execute the following Insert-SQL in MariaDB the JSON-data are stored in a BLOB-field as binary. In order to get the JSON-text I have to select it with COLUMN_GET(..):

INSERT INTO `person` (`ID`, `Data`) VALUES (1, COLUMN_CREATE('Firstname','Max','Lastname','Mustermann'));

SELECT `ID`, COLUMN_GET(`Data`, 'Firstname' AS CHAR) AS Firstname, COLUMN_GET(`Data`, 'Lastname' AS CHAR) AS Lastname FROM `person`;

In mORMot I can also save a JSON-object in a blob-field, but the framework saves it as a text.

Is there a possibility to write/read the JSON in the MariaDB compatible mode?

Thx for your answer!

#111 Re: mORMot 1 » Load/Save a JPEG image from/into a MemoryStream and save it in a file » 2015-03-26 15:17:01

array81 wrote:

I don't have use ColumnBlob until now but the framework don't load the blob by default (to save memory) so you may need to force the blob reading.
TSQLRecord work in this mode.

I know how the blob fields are handled, the code fetches the blob data, i.e. the picture, and I can load it from the stream object into the image-component. The problem is the TSynPicture or the probmlem is me because I can't use TSynPicture in the right way ;-) :-D

#112 Re: mORMot 1 » Load/Save a JPEG image from/into a MemoryStream and save it in a file » 2015-03-26 15:13:45

ab wrote:

You have to run Gdip.RegisterPictures to initialize the GDI+ library.

Run it in the initialization section of your project.

I have tried it and I get a message like "EFilerError : A class named TJpegImage already exists".

Do you have any suggestions why!?

#113 mORMot 1 » Load/Save a JPEG image from/into a MemoryStream and save it in a file » 2015-03-26 11:03:12

cypriotcalm
Replies: 5

Good afternoon!

I have a code like this:

var
  MemStream: TSynMemoryStream;
  JPEGImage: TSynPicture;
begin
  JPEGImage := TJpegImage.Create;

  // DB access to load a JPEG from a database  
  MemStream := TSynMemoryStream.Create(NewStmt.ColumnBlob('JPEGDATA'));
  
  MemStream.Position := 0;
  JPEGImage.LoadFromStream(MemStream);
  JPEGImage.SaveToFile('c:\temp\myimage.jpeg');

  ... 

end;

The problem is an empty file is created after the execution "SaveToFile".

I have debugged this method and saw that TSynLibrary is nil (screenshot 1) and the method "SaveAs(...)" exits before it can save something (screenshot 2).

Screenshot 1: http://s27.postimg.org/5ab8ioilf/gdiplus.jpg
Screenshot 2: http://s27.postimg.org/mp024p543/gdiplus2.jpg


Could you help me? :-)

#114 Re: mORMot 1 » database connection definitions in ini » 2015-03-04 09:35:50

I deserialize a JSON-file as follows:

The input JSON-file ist:

{
    "Kind": "TSQLDBFireDACConnectionProperties",
    "ServerName": "MySQL?localhost;Port=3307",
    "DatabaseName": "general",
    "User": "root",
    "Password": "bJy+bxhysB/eWMpKHsLt63Y9BqM="
}

dbConnProps := TSQLDBFireDACConnectionProperties.CreateFromFile('dbProps.json');

I'll get this result:

dbConnProps.ServerName -> "MySQL" instead of  "MySQL?localhost;Port=3307"

#115 Re: mORMot 1 » database connection definitions in ini » 2015-03-04 08:54:31

I have tested the new feature in the following way:

var
  dbConnProps: TSQLDBConnectionProperties;
begin
  dbConnProps := TSQLDBFireDACConnectionProperties.Create('MySQL?localhost;Port=3307', 'general', 'root', 'suhgUKpH5BLQPxFNvCJl');
  dbConnProps.DefinitionToFile('dbConnDef.json');
end;

The JSON-file looks like:

{
    "Kind": "TSQLDBFireDACConnectionProperties",
    "ServerName": "MySQL",
    "DatabaseName": "general",
    "User": "root",
    "Password": "bJy+bxhysB/eWMpKHsLt63Y9BqM="
}


But if I serialize the properties via TSynConnectionDefinition then I get a result as follows:

  ConnDefFromIni := TSynConnectionDefinition.Create();
  ConnDefFromIni.ServerName := 'MySQL?localhost;Port=3307';
  ConnDefFromIni.User := 'root';
  ConnDefFromIni.DatabaseName := 'general';
  ConnDefFromIni.PasswordPlain := 'suhgUKpH5BLQPxFNvCJl';
  
  JSONSynDef := ConnDefFromIni.SaveToJSON()

Resulted JSON-file:

{
    "Kind":"",
    "ServerName":"MySQL?localhost;Port=3307",
    "DatabaseName":"general",
    "User":"root",
    "Password":"bJy+bxhysB/eWMpKHsLt63Y9BqM="
}

Should be the resulted JSON-file not the same?


Generally, is it possible to get a JSON-File like this?

{
    "Kind": "TSQLDBFireDACConnectionProperties",
    "ServerName": "localhost",
    "Port": 3307,
    "DriverID": "MySQL",
    "DatabaseName": "general",
    "User": "root",
    "Password": "bJy+bxhysB/eWMpKHsLt63Y9BqM="
}

And one more question: if there is a need to change the password directly in a JSON-file without saved it before via "TSQLDBFireDACConnectionProperties.DefinitionToFile(...)". Is there a possibility to encrypt a plain password and to encode it as Base64?


Make it sense to have a functionality to ecnrypt/decrypt the plain passwords outside the application?

#116 Re: mORMot 1 » database connection definitions in ini » 2015-03-04 06:49:33

Wow! Great work, Arnaud! I will take a look at it! Thank you very much for the fast reaction!

#117 mORMot 1 » Best way to map a many-to-many relationship with a cross-table » 2015-03-03 09:01:23

cypriotcalm
Replies: 1

Hi there!

I have three tables in my database, e.g.:

- TStudent (ID, Firstname, Lastname, Age)
- TProf (ID, Firstname, Lastname, Age, Title)
- TLecture (a cross table between TStudent and TProf): in this table I want to save only two references to TStudent and TProf,

What would be the best way to map the cross-table?

1. TLecture
    published
       StudentID: TID;
       ProfID: TID;
    end;

2. TLecture
    published
       Student: TStudent;
       Prof: TProf;
    end;

In the 2d one, what is the best way to load the Student and Prof properties?


Thank you very much for your answer!

#118 Re: mORMot 1 » database connection definitions in ini » 2015-03-02 13:48:19

Is it also possible to serialize the passwort property?

In general, I would like to have a possibility to define the database connection parameters in an external file which I can change without compiling the software? Is it possible to get it done by the framework?

#119 mORMot 1 » database connection definitions in ini » 2015-03-02 12:36:11

cypriotcalm
Replies: 8

Is there in the mORMot framework a possibility to read a connection definition/definitions from an INI/Text-file?

#121 Re: mORMot 1 » Create FireDAC/SQLModel/RestClient for a single MySQL table » 2015-02-25 14:16:04

Thx for your help! Now it works! I have modified a bit the example "28 - Simple RESTful ORM Server".

Is it a right way to map my existing MySQL database in case I don't want to use RESTful?

Could you take a look at it if I am doing it right?


  TMeasurement = class(TSQLRecord)
  private
    fName: RawUTF8;
  published
    /// ORM will create a NAME VARCHAR(80) column
    property Name: RawUTF8 index 80 read fName write fName;
  end;

  TAnalyses = class(TSQLRecord)
  private
    fName: RawUTF8;
  published
    /// ORM will create a NAME VARCHAR(80) column
    property Name: RawUTF8 index 80 read fName write fName;
  end;

  function DataModel: TSQLModel;
  begin
    Result := TSQLModel.Create([TMeasurement, TAnalyses], SERVER_ROOT);
    TMeasurement.AddFilterOrValidate('Name',TSynValidateText.Create); // ensure exists
    TAnalyses.AddFilterOrValidate('Name',TSynValidateText.Create); // ensure exists
  end;

procedure CreateMeasurementAndAnalyses;
begin
  aProps := TSQLDBFireDACConnectionProperties.Create('MySQL?localhost;Port=3306', 'dbname', 'user', 'pass');
  try
    // get the shared data model
    aModel := DataModel;

    // use PostgreSQL database for all tables
    VirtualTableExternalRegisterAll(aModel,aProps);
    try
      aModel.Props[TMeasurement].ExternalDB.MapField('ID','IdMeasurement');
      aModel.Props[TAnalyses].ExternalDB.MapField('ID','IdAnalyses');

      // create the main mORMot server
      aRestServer := TSQLRestServerDB.Create(aModel,':memory:',false);
      try
        // create tables or fields if missing
        aRestServer.CreateMissingTables;

        // create a mORMot client
        aClient := TSQLRestClientDB.Create(aRestServer);
        try
          aMeasurement := TMeasurement.Create;
          try
            Randomize;
            aMeasurement.Name := 'Name'+Int32ToUtf8(Random(10000));
            aID := aClient.Add(aMeasurement,true);
          finally
            aMeasurement.Free;
          end;

          aAnalyses := TAnalyses.Create;
          try
            Randomize;
            aAnalyses.Name := 'Name'+Int32ToUtf8(Random(10000));
            aID := aClient.Add(aAnalyses,true);
          finally
            aAnalyses.Free;
          end;

        finally
          aClient.Free;
        end;
      finally
        aRestServer.Free;
      end;
    finally
      aModel.Free;
    end;
  finally
    aProps.Free;
  end;
end.

#122 mORMot 1 » Create FireDAC/SQLModel/RestClient for a single MySQL table » 2015-02-20 12:23:02

cypriotcalm
Replies: 4

Hi there!

I have just discovered the mORMot framework and I am pretty impressed of it! A good work! *thumbs up*, buuut.... I have a question!

After reading the documantation which is really great I unfortunately wasn't able to map a single MySQL table. I used this code:

type
  TMeasurement = class(TSQLRecord)
  private
    FName: RawUTF8;
  published
    property Name: RawUTF8 read FName write FName;
  end;


procedure SetupDataBase;
var
  dbConnProps: TSQLDBConnectionProperties;
  Model: TSQLModel;
  Client: TSQLRestClientDB;
  MJ: TMeasurement;
begin
  // 1. Populate the FireDAC MySQL ConnectionProperties
  dbConnProps := TSQLDBFireDACConnectionProperties.Create('MySQL?localhost`;Port=3306', 'dbname', 'user', 'pass');

  // 2. Connecting 
  dbConnProps.ThreadSafeConnection.Connect;

  // 3. Create the Model
  Model := TSQLModel.Create([TMeasurement], 'root');

  // 4. Register an external table 
  VirtualTableExternalRegister(Model, TMeasurement, dbConnProps, 'measurement');

  // 5. Create a REST Client
  Client := TSQLRestClientDB.Create(Model, nil, string('SQliteDb.sqlite'), TSQLRestServerDB, false, '');

  // 6. Retrieve data
  MJ := TMeasurement.CreateAndFillPrepare(Client, 'Name LIKE ?',['new measure%']);

  Form1.ListBox1.Items.BeginUpdate;
  try
    while MJ.FillOne do
    begin
      Form1.ListBox1.Items.Add(MJ.Name);
    end;
  finally
    MJ.Free;
    Form1.ListBox1.Items.EndUpdate;
  end;

end;

My questions are:
5. What should I define instead of string('SQliteDb.sqlite') for the MySQL database!?
6. I have an error like "... no such table measurement"


Could you help me? Thx!

Board footer

Powered by FluxBB