Support Forum

Ask questions and get help from MobileTogether experts.
MobileTogether Product Information
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
View
Go to last post Go to first unread
jge  
#1 Posted : Wednesday, August 13, 2014 3:43:40 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

I created a subpage to edit/insert new records to DB3 from XML2. see attached screen. My question are:
1. how to do it in OnButtonPressed, which command I should use here?
2. how to deal with insert new record or edit existing record? if EDIT existing record, the original $XML2/DATASET/@remark_text is not null. I know we should use some kind IF-THEN-ELSE on SAVE button action. just do not know how to do it in this new software.
3. How to use Create OriginalRowset option here? just right click DB3 and select it? Do we need write any code to use it?
my understanding to OriginalRowset, it should store orginal value of DB3 and system will compare its value with new value. if same , do not need write back to DB3, otherwwsie need write back.
jge attached the following image(s):
add0.jpg
add1.jpg
add2.jpg
add3.jpg
bbv  
#2 Posted : Wednesday, August 13, 2014 8:09:41 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
You have two major methods how to save data in the database:

1. By using DB Execute command and writing your own INSERT and UPDATE statements. This method gives you the biggest freedom to manipulate data as you like it. Here you will need the If-Then-Else to decide which DB command to execute.

2. By using Save command to do this automatically. This second method only works if you used an option Create OriginalRowSet. Then, if you add or modify Row elements under RowSet, and execute Save command - MobileTogether will compare RowSet with OriginalRowSet and will produce INSERT, UPDATE, and DELETE statements automatically for you. There is no need for If-Then-Else in this case. Please take a look at the "Connecting Your Database to your Mobile Solution" video here http://www.altova.com/mobiletogether/demos.html - it is using the Save method to save new data.

Feel free to ask if something is still unclear.

What did you mean with the first question "how to do it in OnButtonPressed, which command I should use here?" - how to start editing or save data?


Altova MobileTogether Experts
bbv  
#3 Posted : Wednesday, August 13, 2014 9:27:10 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
One additional hint: if you are using the automatic Save method, then you have to append or update corresponding Row elements. It is much easier if you use for editing the very same structure. What I mean, is that if you rename in $XML2 the element DATASET to Row and change all attribute names, like shipment_gid, to match exactly the names in your DB3 tree - in your case simply capital letter SHIPMENT_GID, then appending a new Row becomes very easy:

Append to Node: $DB3/DB/RowSet
new Node(s): $XML2/Row

If you want to update an existing node, then the easiest would be to delete it first from $DB3/DB/RowSet and then use the same Append command to add a new one. Though it would be also possible to update all attributes of a particular Row in $DB3 with the values from $XML2 in a single Update Node(s) statement too.


Altova MobileTogether Experts
jge  
#4 Posted : Tuesday, August 19, 2014 9:38:05 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

IF we insert/edit something in third subpage (SEE THIRD_PAGE), and go back to second subpage (SECOND_PAGE) to show the result (DB2), how can we do it?
reload function in onButtonPressed in third subpage cant select DB2 in second subpage. That is mean we can't refresh the second subpage contents. Please help.
I put ADD and EDIT 2 button on third page, when user want add new REMARK, they should click ADD button, if they want edit existing REMARK, click EDIT button. I know we should not do this way, I do not know how to make ONE button <SAVE> to do it.
jge attached the following image(s):
second_page.jpg
third_page.jpg
add button.jpg
edit button.jpg
jge  
#5 Posted : Tuesday, August 19, 2014 9:47:16 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

when we click ADD button to append node to DB3 with XM2 data, the program crash. got error see attached.
jge attached the following image(s):
add_error.jpg
bbv  
#6 Posted : Wednesday, August 20, 2014 10:01:37 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
Quote:
reload function in onButtonPressed in third subpage cant select DB2 in second subpage

You need to add DB2 page source to the third sub page, then it will become available for reload.

We would love to help you, but it becomes increasingly difficult to understand what you are doing based just on your screenshots. Can you attach here your design file? Or send it to Altova Support if you don't want to make it public
jge  
#7 Posted : Wednesday, August 20, 2014 2:49:49 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

I attached MY DESIGN details here.
File Attachment(s):
jge  
#8 Posted : Wednesday, August 20, 2014 3:15:19 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

do we need add OriginalRowSet for the DB3 WHICH IS FINAL TABLE TO BE INSERT/EDIT?
jge  
#9 Posted : Wednesday, August 20, 2014 3:29:03 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

HOW SYSTEM smart enough to do update:
update node $DB3/DB/RowSet with $XM2/Row? How can system find which record in DB3 to be updated?
bbv  
#10 Posted : Wednesday, August 20, 2014 4:24:53 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
I've now read through your document. It would be a lot easier to answer you if you could attach (or send to Altova Support) your actual MTD file, but I will try based on your description and questions:

1. This is just a warning: your method for getting the sequence number by using MAX(remark_sequence) and adding 1 to it is dangerous. This is because if you have two drivers editing their records at the same time, they will get the very same sequence number

2. You are using "Go to Subpage event" command from your subpage. Without seeing your MTD file I can only guess that this was the actual error - you only need to Close Subpage, which will return you to your previous subpage, so try to remove the Go to Subpage.

3.
Quote:
do we need add OriginalRowSet for the DB3 WHICH IS FINAL TABLE TO BE INSERT/EDIT?
- if you want to use the Save command, then yes

4.
Quote:
HOW SYSTEM smart enough to do update
Save command uses Primary Key from your database to identify the record. I guess in your case SHIPMENT_GID is such a Primary Key. It then compares all other fields in a Row and OriginalRow with the same PrimaryKey. If any of the other fields changed - it will generate an UPDATE statements for those changed fields. If there is no OriginalRow with the same Primary Key - it will generate an INSERT statement

Now, if you have in $XML2 all fields from a DB3 Row, then you can implement the desired SAVE button instead of ADD/EDIT buttons this way:

Code:
If $XML2/Row/@REMARK_SEQUENCE = ''
Then
   Reload $DB4
   Update Node $XML2/Row/@REMARK_SEQUENCE...

Delete Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID ]
Append Node $DB3/DB/RowSet...
Save $DB3

Reload $DB2
Close Subpage


What happens here - if it was an existing record, then you delete it from the RowSet first and it will be appended by the next Append Node command. If it is a new record, then you set new sequence number and append the node - the Delete Node will do nothing, because there is no existing record.

After all this Save will compare differences between RowSet and OriginalRowSet and propagate your changes to the database.

Important: you can do this trick with Delete Node/Append Node only if $XML2 contains all fields from $DB3 Row, otherwise you will lose some of the field values. If $XML2 does not have all the fields, then you need update every field in $DB3 Row instead of Delete/Append - let me know if I should help you to do this properly.


Altova MobileTogether Experts
jge  
#11 Posted : Wednesday, August 20, 2014 5:00:45 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

the table shipment_stop_remark has three key fileds must be unique:
shipment_gid, stop_num, remark_qual_gid, plus REMARK_SEQUENCE , can we write following statement:

Delete Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID and @STOP_NUM = $XML2/Row/@STOP_NUM and @REMARK_QUAL_GID = $XML2/Row/@REMARK_QUAL_GID]
then
Append Node $DB3/DB/RowSet...?
bbv  
#12 Posted : Wednesday, August 20, 2014 9:53:22 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
Sure!
bbv  
#13 Posted : Friday, August 22, 2014 9:45:01 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
Sorry, forgot to ask: in order to better reproduce your crashes, can you please attach all crash dump files which you can find C:\Users\your-user-name\Documents\Altova\MobileTogetherDesigner...dmp
jge  
#14 Posted : Friday, August 22, 2014 2:36:34 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

attached dmp file here which generated when crashed at insert new record. when save edit record, it did not crash, but not save the result.
I use following command at onButtonPressed for SAVE EDIT:

1. Update Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID and @STOP_NUM = $XML2/Row/@STOP_NUM and @REMARK_QUAL_GID = $XML2/Row/@REMARK_QUAL_GID]
with Result of $XML2/Row/@REMARK_TEXT

2. Save $DB3(DB)

but it did not save.
File Attachment(s):
MobileTogetherDesigner_1.0.b1_20140721.dmp (86kb) downloaded 65 time(s).
jge attached the following image(s):
edit_save.jpg
jge  
#15 Posted : Friday, August 22, 2014 4:03:28 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

ATTACHED SIMULATION LOG file here. There is no any error. but the edit result did not write back to the database server.
In the log file, the row 5198 is original record in the table to be edited. see attached screen.
Update target node '/DB/RowSet/Row[5198]
File Attachment(s):
Simulation_LOG.docx (14kb) downloaded 66 time(s).
jge attached the following image(s):
edit_save_5198.jpg
bbv  
#16 Posted : Saturday, August 23, 2014 6:36:50 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
This statement

Update Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID and @STOP_NUM = $XML2/Row/@STOP_NUM and @REMARK_QUAL_GID = $XML2/Row/@REMARK_QUAL_GID]
with Result of $XML2/Row/@REMARK_TEXT

is not correct. If you don't want the combination of Delete and Append node as I suggested it to you, then you must modify your statement to update the @REMARK_TEXT in your Row and not the Row itself (add /@REMARK_TEXT on the end)

Update Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID and @STOP_NUM = $XML2/Row/@STOP_NUM and @REMARK_QUAL_GID = $XML2/Row/@REMARK_QUAL_GID]/@REMARK_TEXT
with Result of $XML2/Row/@REMARK_TEXT
bbv  
#17 Posted : Saturday, August 23, 2014 6:59:44 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
By the way, by analyzing your SIMULATION LOG, it occurred to me that you load the whole SHIPMENT_STOP_REMARK table with 5600 rows before you start editing Event Entry. This is slow and will be even slower when people will start to use your app with their mobile phones, because this data will have to be transferred to the phone.

Instead, you should use a SELECT statement to load only the records which belong to the current event, i.e.

SELECT * FROM SHIPMENT_STOP_REMARK
WHERE SHIPMENT_GID = :Param_SHIPMENT_GID
AND STOP_NUM = :Param_STOP_NUM
AND REMARK_SEQUENCE = :Param_REMARK_SEQUENCE

with Param_SHIPMENT_GID set to $XML2/Row/@SHIPMENT_GID
Param_STOP_NUM set to $XML2/Row/@STOP_NUM
Param_REMARK_SEQUENCE set to $XML2/Row/@REMARK_SEQUENCE
bbv  
#18 Posted : Monday, August 25, 2014 9:38:11 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
Thank you for the dump file. We have now found the reason for crash and fixed it for the next release.

For you in order to avoid crashes with your current release, open the actions in your Add button, remove Save action and insert a new one. The existing Save action was internally corrupt, and by inserting a new one everything should be fine.

Sorry for inconvenience!
jge  
#19 Posted : Monday, August 25, 2014 4:30:34 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

Thanks for your many good helps.
for edit button, I changed to:
Update Node $DB3/DB/RowSet/Row[ @SHIPMENT_GID = $XML2/Row/@SHIPMENT_GID and @STOP_NUM = $XML2/Row/@STOP_NUM and @REMARK_QUAL_GID = $XML2/Row/@REMARK_QUAL_GID]/@REMARK_TEXT
with Result of $XML2/Row/@REMARK_TEXT , BUT IT STILL NOT SAVE.
Then, I added SAVE Node action after Update Node command. It works now.

For Add button, changed to Insert Node, take out Save Node command as you said.
Not sure what I should select here for Insert Before and new Node. As I understood, new node should be
$XML2/Row (data source)
Insert Before Node: $DB3/DB/RowSet

$DB3 WHICH is destination table, since you suggested using select statement, instead of whole table shipment_stop_remark(which has 5000+ records)
It did not insert new record.

I attached dmp and mid files also for your review.
File Attachment(s):
MobileTogetherDesigner_1.0.b1_20140721.dmp (83kb) downloaded 62 time(s).
jge attached the following image(s):
insert_before.jpg
insert_ready.jpg
insert_after.jpg
jge  
#20 Posted : Monday, August 25, 2014 4:36:36 PM(UTC)
jge

Rank: Advanced Member

Groups: Registered
Joined: 7/31/2014(UTC)
Posts: 40
Location: sterling, VA

the $DB3 is blank for insert function, since there is no any record at that moment for that select statement:
SELECT * FROM SHIPMENT_STOP_REMARK
WHERE SHIPMENT_GID = :Param_SHIPMENT_GID
AND STOP_NUM = :Param_STOP_NUM
AND REMARK_SEQUENCE = :Param_REMARK_SEQUENCE

with Param_SHIPMENT_GID set to $XML2/Row/@SHIPMENT_GID
Param_STOP_NUM set to $XML2/Row/@STOP_NUM
Param_REMARK_SEQUENCE set to $XML2/Row/@REMARK_SEQUENCE

That is why I original select whole table for DB3 which has thousand records, instead of select statement.
I know select whole table is slow down performance, just do not know if we can use select statement here.
File Attachment(s):
Simulation_LOG_20140824110000.docx (15kb) downloaded 63 time(s).
Users browsing this topic
2 Pages12>
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.