#51 mORMot 1 » How to implement a TSQLRecord descendant w a property of TObjectList ? » 2013-11-12 16:51:29

wai-kit
Replies: 13

Hi,

I am trying to find out what I need to do to implement a class with a property of TOBjectList.

My classes looks like

TSQLPlayer = class(TSQLRecord)
...
end;

TListPlayer = TObjectList<TSQLPlayer>;

TSQLGame = class(TSQLRecord)
private
   fPlayers:TListPlayer;
...
published
   property Players:TListPlayer read fPlayers write fPlayers;
end;

This codes compiles with no errors; But in runtime I get the following exception:
EORMException with message 'Unhanled type for property Players'.

This happens in TSQLModel.Create([TSQLGame, TSQLPlayer], 'root');

Did I failed to do some initialization here?

Merci,

Wai

#52 Re: mORMot 1 » Lazarus support » 2013-09-23 14:44:19

A wizard would definitely aide in adopting lots of mORMots smile.

#53 Re: mORMot 1 » Lazarus support » 2013-09-23 08:41:53

Maybe FPC support can be implemented in two phases? First the client side, then the server?

#54 Re: mORMot 1 » My mORMot Videos » 2013-09-07 14:01:48

Where is the like button big_smile ...

#55 Re: mORMot 1 » how to pass string from Smart Mobile to Mormot? » 2013-09-07 13:59:36

The 5 MB file is no problem to download. It is quite fast.

#56 Re: mORMot 1 » My mORMot Videos » 2013-09-06 08:55:13

Great videos, if only they played a littel bit slower ...

#57 Re: mORMot 1 » how to pass string from Smart Mobile to Mormot? » 2013-09-06 08:46:53

Yes, changing from RawJSON to RawUtf8 solved the problem.
Merci, Arnaud.

Also cool, that I don't have to log in to get the latest source. The Nightbuilds are really handy.

#58 mORMot 1 » how to pass string from Smart Mobile to Mormot? » 2013-09-05 09:57:03

wai-kit
Replies: 4

Hi everyone,

I have a client made with Smart Mobile Studio and a Mormot server communicating through an interface. This setup is build on
the units written by LoPiTaL.  I am sending JSON string from the client to the server. When accessing this string (using JSONToObject)
I get an access violation. Tracing into JSONToObject I
see that the string is "", although in the debugger the string passed from the client is shown.
In the client, the parameter is declared as string and in mormot it is RawJSON.
Does anyone have an idea what is happening and what is the correct way to pass string args?

Thanks in advance,
Wai

#59 mORMot 1 » Maybe time for a FAQ section? » 2013-06-16 11:28:39

wai-kit
Replies: 1

Hi guys,

What are your thoughts about a FAQ section for mORMot?

Cheers,
Wai

#60 Re: mORMot 1 » Change password » 2013-06-16 11:20:21

So this snippet of code should change the password of the default user?

  fServer := TSQLRestServerFullMemory.Create(fModel,'.\test.json',false,true);
  fServer.CreateMissingTables(0);
  aMormotUser := TSQLAuthUser.Create(fServer, 'Name=?', ['User']);
  aMormotUser.PasswordPlain := 'NewPasswd';
  assert( fServer.Update(aMormotUser), 'Default User password not changed!');

Unfortunately, the assert fails. What else needs to be done, so the password is changed? Or is this not the way to go?

#61 Re: mORMot 1 » Authentication: Adding new user » 2013-06-04 09:33:16

ab wrote:

RTFM!

big_smile

Indeed RTFM (or RTFF smile ), if i knew what to look for. I search in the SAD for 'http.sys', 'authorize', but not AddUrlAuthorize. Unfortunately,
my pdf reader cannot do partial searches.

This brings me to these questions:
- when using mORMot authentication scheme, do I have to use sqlite3 for persistence?
- is it also possible to use an external database for user/pw persistence?

It might be that these questions has already been answered, so feel free to RTFM me big_smile.

#62 Re: mORMot 1 » Authentication: Adding new user » 2013-06-03 09:17:44

hi MPV, thanks for clarifying.

I have noticed that the EOSError only occurs when running 'this' Project04client in Delphi and not when running the executable. When I run a Project04client from
a different sample then also no problem.
I then decided to remove Project04Client from the project group, delete all files generated by Delphi (.dproj, .res) and added the project back to the project group.
And then no problem ...

#63 Re: mORMot 1 » Authentication: Adding new user » 2013-06-02 16:16:26

The URI is registerer in :

procedure TForm1.FormCreate(Sender: TObject);
begin
  Model := CreateSampleModel;
  DB := TSQLRestServerDB.Create(Model,ChangeFileExt(paramstr(0),'.db3'),true);
  DB.CreateMissingTables(0);
  Server := TSQLHttpServer.Create('8080',[DB],'+',useHttpApiRegisteringURI);
  Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;

Right?

#64 Re: mORMot 1 » Authentication: Adding new user » 2013-05-30 14:04:08

When running only the executables, everything is fine. When running the client in IDE, the EOSError (Systemerror, Code 12002) appears.

#65 Re: mORMot 1 » Authentication: Adding new user » 2013-05-28 18:53:15

Ah, sorry. I was not clear on which side it is. This is on the server side.

#66 Re: mORMot 1 » Authentication: Adding new user » 2013-05-28 11:33:26

ahaa, so that is why the field Grouprights in table authuser has such a big number instead of the value 3. (Learned something new again, usage of MainFieldID)
allright, so now i have made the suggested changes and now I see the value 3 in the grouprights field.
The new code looks like:

procedure TForm1.Button2Click(Sender: TObject);
var
  aNewUser:TSQLAuthUser;
begin
  aNewUser := TSQLAuthUser.Create;

  try
    aNewUser.PasswordPlain := edit2.Text;
    aNewUser.LogonName := edit1.Text;
    aNewUser.DisplayName := edit1.Text;

    aNewUser.Grouprights := pointer(DB.MainFieldID(TSQLAuthGroup,'User'));

    if DB.Add(aNewUser, true)<>0 then begin
      showmessage('User '+ aNewUser.LogonName + ' added.');
    end;
  finally
    aNewUser.Free;
  end;

end;

Now the issue is that when I add a new user to the database and in the client I use SetUser('User', 'synopse') everything works according to plan. But, when
I use SetUser('wai', 'test') I cannot add any data with the client. When running the client in Delphi I see that an EOSError (message 'System error. Code 12002') occurs.
Tracing the call I see that this happens at

lineno 21572.        aNonce := CallBackGetResult('auth',['UserName',U.LogonName]);

in unit mORMot.

#67 mORMot 1 » Authentication: Adding new user » 2013-05-27 11:24:56

wai-kit
Replies: 14

Hi all,

I am looking into the authentication mechanism of mORMot. Just checking if I am on the right track.
For this purpose I have modified Sample 4.
I have put 2 Tedit and a Tbutton component to the form of the server. When the button is clicked a new user is added
to the database. Below is the code snippet in the onclick eventhandler of the button.

procedure TForm1.Button2Click(Sender: TObject);
var
  aNewUser:TSQLAuthUser;
begin
  aNewUser := TSQLAuthUser.Create;

  aNewUser.PasswordPlain := edit2.Text;
  aNewUser.LogonName := edit1.Text;
  aNewUser.GroupRights := TSQLAuthGroup.Create(DB, 'Ident=?', ['User']);

  if DB.Add(aNewUser, true)<>0 then
    showmessage('User '+ aNewUser.LogonName + ' added.');
end;

When checking project04server.db3 with SqliteMan, I see that a corresponding record has been created in table AuthUser.

Unfortunately, when starting the client (in Delphi XE) an EOSException is raised with message 'System Error. Code 12002' at

  TSQLHttpClient(Form1.Database).SetUser('wai','test');

When I try to delete the new record in table AuthUser with SqliteMan I get a notification that I cannot commit because a pending
transaction is in progress.

What am I missing? Remarks and tips much appreciated.

Thanks,
Wai

#68 Re: mORMot 1 » My first webservice with mORMot » 2013-05-26 09:15:30

Nice video.
An example on how to implement authentication in mORMot is much appreciated.

#69 Re: mORMot 1 » Using SynDBZeos. » 2013-05-06 15:34:47

back again fiddling with SynDBZeos.

so when using function URI of TSQLDBZEOSConnectionProperties the function call would look like:

  fDatabase := TSQLDBZEOSConnectionProperties.Create(TSQLDBZEOSConnectionProperties.URI(dMySQL, 'libmysql.dll'),
                                                DatabaseProperties.DatabaseName,
                                                DatabaseProperties.Username,
                                                DatabaseProperties.Password );

I assume I have to provide the name of the MySQL lib, 'libmysql.dll' to the function.

Now I get an EZSQLException with the message 'Requested database driver was not found'. In my code this exception is raised at this statement:

res := fDatabase.ExecuteInlined(aSQLQuery, true);

aSQLQuery being a valid SQL statement.

If I inspect fDatabase, I see that fServerName is 'mysql'. Shouldn't this be
the name of the server where MySQL is running?

#70 Re: mORMot 1 » JSONToDataset raise EVariantTypeCastError » 2013-04-17 07:42:26

That did the trick.

Kudos for the fast response ...

#71 mORMot 1 » JSONToDataset raise EVariantTypeCastError » 2013-04-16 21:20:02

wai-kit
Replies: 3

Hi,

Has anybody come across this error before: EVariantTypeCastError : could not convert variant of type (UnicodeString) into type (Double)? I get this error when calling
JSONToDataset with this JSON string:

'[{"folio_id":11111,"folio_name":"testfolio 1","startDate":"2013-01-01","closedDate":"2013-01-02","description":null,"startCapital":null,"endCapital":null,"RiskValue":null},
{"folio_id":22222,"folio_name":"testfolio 2","startDate":"2013-01-01","closedDate":null,"description":null,"startCapital":null,"endCapital":null,"RiskValue":null}]'

Whereas with this JSON the error is not raised:

'[{"folio_id":11111,"folio_name":"testfolio 1","startDate":"2013-01-01","closedDate":null,"description":null,"startCapital":null,"endCapital":null,"RiskValue":null},
{"folio_id":22222,"folio_name":"testfolio 2","startDate":"2013-01-01","closedDate":null,"description":null,"startCapital":null,"endCapital":null,"RiskValue":null}]'

The only difference between the two JSON strings is "closedDate":"2013-01-02" and "closedDate":null. The error is raised when converting a to a DateTime field.

I am using the latest version of mORMot.

Regards,

Wai

#72 Re: mORMot 1 » Building JSON client with mORMot. Possible? » 2013-03-31 17:25:36

Merci beaucoup for the tip. This one has put me on route again smile.

#73 mORMot 1 » Using SynDBZeos. » 2013-03-31 17:01:23

wai-kit
Replies: 3

Hi Arnaud,

I'm trying to use SynDBZeos to connect to a MySQL Database using the following:
   fDatabase:TSQLDBConnectionProperties;
   ...
   ...
   fDatabase := TSQLDBZEOSConnectionProperties.Create(ServerName, Databasename, Username, Password);

Servername is the hostname of the computer, Databasename is the databasename as created in MySQL, etc. etc.

The create seems to be executed without a problem, but when I get to 'res := fDatabase.ExecuteInlined(aSQLQuery, true);' I get a
EZSQLException with the message 'Requested Database driver was not found'. Apparently, it is unknown what the database is.

The question is, how do I provide the information to the constructor that the database is a MySQL database?

Cheers,
Wai

#74 Re: mORMot 1 » Building JSON client with mORMot. Possible? » 2013-03-31 08:58:50

To connect a HTTP client I need to pass a TSQLModel as one of the arguments:

   client := TSQLHTTPClient.create(ServerAddres, ServerPort, Model)

Can I simply pass nil as Model?

As for JSON, I will be using the JSONtoDataset routines.

#75 mORMot 1 » Building JSON client with mORMot. Possible? » 2013-03-30 08:30:10

wai-kit
Replies: 4

Hi everyone,

I want to create a client that can consume webservices other than those created with the mORMot framwework. These
webservices communicates through JSON.

Is this possible and what steps do I need to take?

Thanks,
Wai

#76 Re: mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-28 13:58:57

Hi Eraldo,

The solution is already explained in post #6 and #7 in this thread.

Cheers,
Wai

#77 Re: mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-28 09:55:18

Guess I didn't read the small letters in the documentation :-).
Thanks for the info, Arnaud.

Cheers,
Wai

#78 Re: mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-27 22:54:47

I just discovered that the following statements produces the error:

  fTableJSON := fService.GetCountries;
  aTable := TSQLTableJSON.Create([],'',pointer(fTableJSON),Length(fTableJSON));
  TSQLTableToGrid.Create(StringGrid1, aTable,fClient);
  DataSource1.DataSet := JSONToDataSet(Self, fTableJSON, fClient);

Whereas :

  fTableJSON := fService.GetCountries;
  DataSource1.DataSet := JSONToDataSet(Self, fTableJSON, fClient);

gives no error and produces the correct output i.e. the dbgrid connected to Datasource1 showing the
correct data.

#79 Re: mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-27 22:27:27

I got the version from 26/3.

I just got the latest version from 27/3. Unfortunately, the error still get raised. Also the JSON message is incomplete. Instead of the previous
JSON message I now get : [{"Country_code

#80 Re: mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-27 08:28:12

The JSON data looks like this:

[{"Country_code":"AUS","name":"Australia","currency":"AUD"},{"Country_code":"CAN","name":"Canada","currency":"CAD"},{"Country_code":"CN","name":"China","currency":"RMD"},{"Country_code":"DE","name":"Germany","currency":"EUR"},{"Country_code":"FR","name":"France","currency":"EUR"},{"Country_code":"HK","name":"Hong Kong ","currency":"HKD"},{"Country_code":"JP","name":"Japan","currency":"YEN"},{"Country_code":"NL","name":"The Netherlands","currency":"EUR"},{"Country_code":"UK","name":"Great Britain","currency":"PND"},{"Country_code":"US","name":"The United States of America","currency":"US"}]

I have also tried the code from example 16:

  aTable := TSQLTableJSON.Create([],'',pointer(fTableJSON),Length(fTableJSON));
  TSQLTableToGrid.Create(StringGrid1, aTable, fClient);

The data is displayed nicely in the grid.

#81 mORMot 1 » EdatabaseError using JSONToDataset » 2013-03-26 19:19:47

wai-kit
Replies: 12

Hi everyone,

I have this function as part of an interface (IStockPortfolio) on my server :

fDatabase: TSQLDBConnectionProperties;

function TStockPortfolio.GetSQLQueryResults(aSQLQuery:RawUTF8):RawJSON;
var
  Res:ISQLDBRows;
begin
  if fDatabase=nil then
    ConnectDatabase;

  res := fDatabase.ExecuteInlined(aSQLQuery, true);

  if res=nil then
    result := ''
  else
    result := res.FetchAllAsJSON(true);
end;


On the client, I would like to do the following:

  fTableJSON := fService.GetSQLQueryResults('SELECT * FROM country');
  DataSource1.DataSet := JSONToDataSet(Self, fTableJSON, fClient);

An EDatabaseError get raised in the JSONToDataset with message 'No fields defined. Cannot create dataset'.

What seems to be the problem here?
Any help much appreciated.


Cheers,
Wai

#82 Re: mORMot 1 » Documentation of the Synopse SQLite3 / mORMot Framework » 2013-01-01 12:56:01

Hi Arnaud,

My compliments for the excellent mORMot Framework and the documentation.

Going through the SAD pdf document, what I missed the most in the functionality of the documentation is
the lack of hyperlinks in the documentation. I find it helpful to go deeper into a subject that I was reading and
be able to jump back.
Is there any chance some kind of a Wiki Doc being setup in the future?

Just my two cents ...

Thanks,
Wai

Board footer

Powered by FluxBB