1. Alexis Colon Lugo
  2. Valentina Server
  3. Montag, Dezember 30 2019, 07:55 PM
  4.  Abonnieren via E-Mail
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
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
sorry i think i fund the error now
is no have the move next record so the index crash

thanks
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
NO same error and i add the Rs.MoveNext
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
this is the only record in the raspberry pi on valentine server with sqlite
Anhänge
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
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
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
ok
But i have to run any other procedure like close and then reopen connection ?
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
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
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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?
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
Hi i have to call Xojo.Net.HTTPSocket.SendProgress (Yes / No) before send next record ?
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
i get http status error 400

I need to finish this project the i start.
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
ok
so how i do multiple records at once in one query.
ii try sql += but show error ?
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
hi
if no other way to connect to valentina sqlite server with out using Rest from iOS app
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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?
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
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.
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Hello,

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


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