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
thanks Sergey you the best help
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
after send some record i call mCloseSocket and the app crash

Can't reproduce anything like that, it is possible to debug step by step the CloseConnectionSocket to find out the line with an issue.

==
I attached a modified project where parameters are used.


Dim params() As Auto
Dim row1() As Auto
Dim row2() As Auto

row1.Append( 10000 )
row1.Append( "first1" )
row1.Append( "last1" )
row1.Append( "000" )

row2.Append( 10001 )
row2.Append( "first2" )
row2.Append( "last2" )
row2.Append( "000" )

params.Append(row1)
params.Append(row2)

mSQLSocket.Start( _
App.mHost,_
App.mSessionID,_
sqlLocation,_
"SQLite",_
"sqlite_sakila.sqlite",_
"INSERT INTO actor ( actor_id, first_name, last_name, last_update ) VALUES ( ?1, ?2, ?3, ?4 );",_
params)


With this approach, we send a single query and pass multiple records (2 in this example).
It is the most efficient way for such a task.
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
Now no more crash but only one record at same time
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
ok
thanks
after send some record i call mCloseSocket and the app crash with out error number i have no idea way.
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Yes, the problem with this approach.

But you can send multiple records in single INSERT:
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');

Additionally, you can use bound parameters, I'll show an example later (this would be the most efficient way).
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Ok, we'll recheck it
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
In Valentina Studio it insert 2 record is perfect but when i send using iOS app it only insert 1 record
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Did you check the sql value in debugger? You should be able to copy/paste it to Valentina Studio.
Any message in Valentina Server log?
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
like this
sql=sql + "INSERT INTO AsambleaSocios (nombre,numsocio,fecha,hora,firma,sync,distrito) VALUES ('"+ v1 + "','"+ v2 + "', '" + v3 + "', '" + v4 + "', '" + pic_as_text + "','Y','" +v5 + "');"
no works
Kommentar
There are no comments made yet.
Alexis Colon Lugo Akzeptierte Antwort
Ok
let my try
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
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
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.
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.
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.
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.
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
i get http status error 400

I need to finish this project the i start.
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
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.
  • Seite :
  • 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