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
thanks Sergey you the best help
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 1
Sergey Pashkov Accepted Answer
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.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 2
Alexis Colon Lugo Accepted Answer
Now no more crash but only one record at same time
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 3
Alexis Colon Lugo Accepted Answer
ok
thanks
after send some record i call mCloseSocket and the app crash with out error number i have no idea way.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 4
Sergey Pashkov Accepted Answer
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).
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 5
Sergey Pashkov Accepted Answer
Ok, we'll recheck it
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 6
Alexis Colon Lugo Accepted Answer
In Valentina Studio it insert 2 record is perfect but when i send using iOS app it only insert 1 record
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 7
Sergey Pashkov Accepted Answer
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?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 8
Alexis Colon Lugo Accepted Answer
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
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 9
Alexis Colon Lugo Accepted Answer
Ok
let my try
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Server
  3. # 10
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.
  1. more than a month ago
  2. Valentina Server
  3. # 11
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.
  1. more than a month ago
  2. Valentina Server
  3. # 12
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.
  1. more than a month ago
  2. Valentina Server
  3. # 13
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.
  1. more than a month ago
  2. Valentina Server
  3. # 14
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.
  1. more than a month ago
  2. Valentina Server
  3. # 15
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.
  1. more than a month ago
  2. Valentina Server
  3. # 16
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.
  1. more than a month ago
  2. Valentina Server
  3. # 17
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.
  1. more than a month ago
  2. Valentina Server
  3. # 18
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.
  1. more than a month ago
  2. Valentina Server
  3. # 19
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.
  1. more than a month ago
  2. Valentina Server
  3. # 20
  • 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