#3 mORMot 1 » Newbie question for MSSQL connection » 2014-07-25 07:58:04

chula
Replies: 10

I have made it to work. Just want to make sure if I was doing right:-

In order to use MSSQL in ORM way, I must create an Embedded Sqlite3 DB as a bridge, and map each Sqlite3 table as virtual table to MSSQL Physical Table by VirtualTableExternalRegister()?

If it is the case, the virtual tables on Sqlite3 can be come from different back-end database servers? Can the Begin/End Transaction  still work?

#4 Re: mORMot 1 » What is the correct way to rename a table/field without loosing data? » 2014-07-25 02:40:25

edwinsn wrote:

If you use SQLite as the backend databae, SQLite itself doesn't support renaming a field.

Assume you have TSQLOldTable, now create a new class called TSQLNewTable with the new field definitions, call CreateMissingTables(); Then read old records from TSQLOldTable and add to TSQLNewTable;

drop tale  TSQLOldTable.

Then change all references to TSQLOldTable in your code to TSQLNewTable.


Very thanks!

As I am new to the framework, do I have to copy the table by looping read/write progress, or there is a more effective way provided from the framework?

#5 mORMot 1 » What is the correct way to rename a table/field without loosing data? » 2014-07-24 09:05:50

chula
Replies: 6

Renaming table/field name in Object definition just create new table/field. Changing field type, say change Integer to RawUTF8, gave nothing happen at all.

What is the correct way to do this? I read from other post someone execute "Alter Table" before CreateMissingTables(). Is it the correct way? Thanks!

#7 Re: mORMot 1 » How to reference a JSON value when the key name is numeric? » 2014-07-04 10:35:28

ab wrote:

You can use DocVariantData(v.result.data).Value['1000'].

I just added the aDocVariant.Value(aName) and aDocVariant._(aName) pseudo methods, which can be used with late-binding.
So that now you can write also: v.result.data.Value('1000') since v.result.data.1000 won't compile.
See http://synopse.info/fossil/info/47805bc15e118


Really cool, thanks very much!

#8 mORMot 1 » How to reference a JSON value when the key name is numeric? » 2014-07-04 09:57:18

chula
Replies: 2

say v := _JSON('{result:{data:{"1000":"D1", "1001":"D2",..........


v.result and v.result.data return properly.

v.result.data.Exists('1000') returned True. Of course there is no  v.result.data.1000 syntax.

How to get the value of key '1000'?

Thanks!

#9 Re: mORMot 1 » Newbie need help in JSON » 2014-07-04 09:17:31

Sorry, I have overlooked your words: " stored not as string/UnicodeString by as RawUTF8", the Chinese chars were reserved when I consumed them, although they looks corrupted when I investigate the variant content.

But the With BOM problem still persists.

#10 Re: mORMot 1 » Newbie need help in JSON » 2014-07-04 08:04:38

ab wrote:

Why are you using a TStringStream here?

Just use

v := _jsonfast(StringFromFile('something.json'));

It will be just faster and less error-prone.

For streaming pure UTF-8 content, I would rather use our TRawByteStringStream.
It will avoid any slow conversion to UTF-16 as with the regular TStringStream.

Within the TDocVariant, be aware that the UTF-8 content is stored not as string/UnicodeString by as RawUTF8.
But it should preserve the Chinese characters as expected.

Thanks! v := _jsonfast(StringFromFile('something.json')); is more concise.

However, the Chinese chars are still corrupted. My test results were:
1. if the JSON file is UTF8 encoded WITH BOM, v is unassigned. Seems error occurred.
2. if the JSON file is UTF8 encoded WITHOUT BOM, v stored the JSON correctly with the Chinese chars corrupted.

(I used Notepad++ to change the encoding of the JSON file, and I am using Delphi XE)

In case you want to take a try, this are my characters inside the JSON file:

{"msg":"","success":true,"result":{"data":{"1000":["垛","垜"],"1001":["坨","垚"]}}}

#11 Re: mORMot 1 » Newbie need help in JSON » 2014-07-04 07:26:02

ab wrote:

The 1.18 SAD PDF has a full per-unit help description.

Take a look at TDocVariant in the SAD.
See also http://blog.synopse.info/post/2014/02/2 … riant-type

Thanks for the info and I could make it work now. However, I run into an encoding problem:

var
  v: variant;
begin
  with TStringStream.Create('', TEncoding.UTF8) do
  try
    LoadFromFile('something.json');
    memo1.Lines.text := DataString;

    v := _json(DataString);
    //v := _json(StringToUTF8(DataString));

  finally
    free;
  end;

I have the JSON file that was UTF8 encoded, so I created the TStringStream with UTF8 encoding and display it firstly inside a Memo in order to make sure the encoding was correct.

No matter I added StringToUTF8/UTF8ToString or not, the variant resulted from _json corrupted my Chinese characters.

What should I do please?

#12 mORMot 1 » Newbie need help in JSON » 2014-07-04 03:19:16

chula
Replies: 7

I am still playing around with mORMot framework........amazing framework....

I have heavily used SuperObject for JSON manipulation. Now I want to study the JSON features of mORMot and found there is no separate Class Reference or Help file.

Anyway I have looked into the SAD document and tried to find a JSON function equivalent to TSuperObject.ParseString(). Maybe I had overlooked, I only found functions which require passing TypeInfo (i.e. know the JSON structure beforehand) or found xxxxxRead() functions that could read JSON string saved by xxxxSave() functions.

Say the JSON string returned from our server has many levels depth, and I just want the data started from level 3 with field name "data". I don't want to build a big Record structure before I can use just the sub-sub-sub Record field, like the RecordLoadJSON().

So, which function can read a random JSON string into a mORMot JSON object? Thanks!

#14 mORMot 1 » A question on Interfaced Service » 2014-06-25 01:11:30

chula
Replies: 2

I have gone through all the samples, it is absolutely cool and very useful framework.

Just wondering, if possible, how to consume the interfaced service like ICalculator, for example, from Delphi Prism, C# and Javascript? Or I must made the service RESTful if it maybe called by language other than Delphi?

Thanks!

#15 Re: mORMot 1 » .CreateMissingTables(0); Access Violation in 02 - Embedded SQLite3 ORM » 2014-06-19 08:15:19

Really thanks for fast response.

Was trying to delete this thread. I found I have another sqllite objects on searching path earlier than mORMot. It has been fixed. Thanks!

#16 mORMot 1 » .CreateMissingTables(0); Access Violation in 02 - Embedded SQLite3 ORM » 2014-06-19 07:28:30

chula
Replies: 2

Hello, again.

I have tried out sample 2 and got AV error at

TSQLRestServerDB(Form1.Database).CreateMissingTables(0);

I used 1.18 NightlyBuild and had downloaded sqlite3.obj and sqlite3fts3.obj (sqlite3obj.7z) from your website to the mORMot source directory.

Please help.

#17 Re: mORMot 1 » Hello Magic??? » 2014-06-19 07:14:31

Sorry, it's my fault.

I traced and found the JSON file, I was accidentally clicked "Add" when the message box was " Not Found". Even I add other "Hello"s, it returned only the first one.

#18 mORMot 1 » Hello Magic??? » 2014-06-18 03:49:33

chula
Replies: 3

Hello,

Just downloaded mORMot and gave it a try, the "01 - In Memory ORM" example.

It worked properly except when the Name is "hello"

  TSQLSampleRecord = class(TSQLRecord)
  private
    fQuestion: RawUTF8;
    fName: RawUTF8;
    fTime: TModTime;
  published
    property Time: TModTime read fTime write fTime;
    property Name: RawUTF8 read fName write fName;
    property Question: RawUTF8 read fQuestion write fQuestion;
  end;

 Rec := TSQLSampleRecord.Create(Database,'Name=?',[StringToUTF8(NameEdit.Text)]);

i.e. As log as NameEdit.Text = 'Hello', the record could not be found. Why so strange?

Board footer

Powered by FluxBB