1. Alexis Colon Lugo
  2. Valentina Server
  3. Monday, December 30 2019, 07:55 PM
  4.  Subscribe via email
Send data from iOS On XOJO
This code works but it send only one record then have a error but k'now the error and the app close.
Any idea what is the problem
Thanks


Var sqlLocation As Text = App.mSessionURL + "/sql_fast"
Var v1,v2,v3,v4,v5,pic_as_text,er As Text
Var Rs As iOSSQLiteRecordSet
Var SqlStr As Text

SqlStr="Select * From AsambleaSocios Order BY numsocio"

Try
Rs=App.DBConn.SQLSelect(SqlStr)
Catch e As iOSSQLiteException
//ErrorLabel.Text = e.Reason
er= e.Reason
End Try

If Rs.RecordCount > 0 Then

Do

v1=Rs.Field("nombre";).TextValue
v2=Rs.Field("numsocio";).TextValue
v3=Rs.Field("fecha";).TextValue
v4=Rs.Field("hora";).TextValue
pic_as_text=Rs.Field("firma";).TextValue
v5=Rs.Field("distrito";).TextValue


Var sql As text = "INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('"+ v1 + "','"+ v2 + "', '" + v3 + "', '" + v4 + "', '" + pic_as_text + "','Y','" +v5 + "')"

mSQLSocket.Start( App.mHost, App.mSessionID, sqlLocation, "SQLite", "ipadcrnew.db",sql)

Loop Until Rs.EOF=True

End If
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
sorry i think i fund the error now
is no have the move next record so the index crash

thanks
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
NO same error and i add the Rs.MoveNext
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
this is the only record in the raspberry pi on valentine server with sqlite
Attachments (1)
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Hello,

Without using REST - does it crash?
What if you try to gather values for multiple records in sql variable without sending to REST - does it have what you need? Then you can send it at once, it will be much faster than separate request.
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
I need to sync the data with my raspberry pi server of Rest ?
can you explain more details on how to do it.

If you have other way to do this then send my example of code.

thanks
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
No need to execute each line separately.

Var sql As text = "INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('"+ v1 + "','"+ v2 + "', '" + v3 + "', '" + v4 + "', '" + pic_as_text + "','Y','" +v5 + "')"

Declare sql variable out of the loop at the top and add values at each iteration:
sql += "INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('"+ v1 + "','"+ v2 + "', '" + v3 + "', '" + v4 + "', '" + pic_as_text + "','Y','" +v5 + "');"

Now make sure you have all records in the sql variable - view in the debugger.

Then you can send them. If the records become too much you just split it into a few parts.
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
ok
But i have to run any other procedure like close and then reopen connection ?
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
same problem using
sql += "INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('"+ v1 + "','"+ v2 + "', '" + v3 + "', '" + v4 + "', '" + pic_as_text + "','Y','" +v5 + "');"
crash with no error
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Connection to the server - no need to close.
Try to debug step by step - at which point it crashes? Before making the REST call or after?
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
the problem is in the loop i call this mSQLSocket.Start( App.mHost, App.mSessionID, sqlLocation, "SQLite", "ipadcrnew.db",sql) but work if i exit the loop it save one record so is no way to call PageReceived and then send the next record.
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
Hi i have to call Xojo.Net.HTTPSocket.SendProgress (Yes / No) before send next record ?
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
i get http status error 400

I need to finish this project the i start.
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
It is an event, so no, you can't call it.

http://docs.xojo.com/Xojo.Net.HTTPSocket

Unlike the classic HTTPSocket, Xojo.Net.HTTPSocket does not support synchronous usage. It only works asynchronously by using the events as described below.

Do not attempt to re-use a socket that is still in use (e.g. directly from the PageReceived or FileReceived events). One solution is to use a separate Timer that checks if the socket is available before attempting to use it again, but for bests results you will probably want to create a new socket.


So you have to use events to know whether a socket is still in use.
But I recommend sending multiple records at once in one query - after the loop, that will be much quicker.
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
ok
so how i do multiple records at once in one query.
ii try sql += but show error ?
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
hi
if no other way to connect to valentina sqlite server with out using Rest from iOS app
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Hello,
No other way.

Just separate records with ; and you can send it at once, you can try generated query in VStudio to see how it works:
INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('v1','v2', 'v3', 'v4', 'pic_as_text','Y','v5');
INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('2-v1','2-v2', '2-v3', '2-v4', '2-pic_as_text','Y','2-v5');


Or you can even join it in one statement
INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('v1','v2', 'v3', 'v4', 'pic_as_text','Y','v5'),  ('2-v1','2-v2', '2-v3', '2-v4', '2-pic_as_text','Y','2-v5');


Do you generate such query?
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Also, how many records are going to be copied?

You still probably need to split records if this number is too big (like more than 1000).
In that case, you have to check if the previous part was received, here's how it is recommended:
https://forum.xojo.com/45262-wait-until-xojo-net-httpsocket-finish

You probably need to create a separate socket variable for sync, and in PageReceived add command to load the next part.
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
Hi
thanks this works You probably need to create a separate socket variable for sync, and in PageReceived add command to load the next part.
uno problems is only can send uno record at the time but is working find.
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Hello,

But why just one record?
What if you send few INSERTS separated with ; ?
Comment
There are no comments made yet.
Alexis Colon Lugo Accepted Answer
Ok
let my try
Comment
There are no comments made yet.
  • Page :
  • 1
  • 2


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories