B4A Library [Class] DBMySQL connect via MySQL Tunnel

aalekizoglou

Member
Licensed User
Longtime User


You are right on this. As I said in the my first post, I have not dealt with the UI correctness. In a real application if you tap on add and then tap on Back without saving the dataset, then you should call cancel after you've created a hock on back key. Maybe present a MsgBox as well with a question.
 

aalekizoglou

Member
Licensed User
Longtime User

aalekizoglou

Member
Licensed User
Longtime User

Images into BLOB fields were way too difficult to develop since I needed to incorporate base64 encoding/decoding. I am not sure what will happen with various devices and different camera settings. But anyway I am here to help on this, since I want to develop a more stable version.
 

aalekizoglou

Member
Licensed User
Longtime User

jiangsaw,

I suppose there is an error in you web server apache/php to connect to mysql without providing the MySQL port number. Before running the request from B4A, try to run from your browser something like

B4X:
http://[YOUR_URL]/mysqltunnel.php?host=192.168.0.6&port=3306&charset=utf8&dbname=test&username=xxxx&password=xxxxxx&query=SELECT * FROM contact

If this works, you might change
B4X:
MySQLConnection.Initialize("http://webservices.mymanager.gr/mysqltunnel.php", "127.0.0.1", "", "qualisys_demodb", "qualisys_demodb", "12345!@#$%", "utf8", True, "")
to
B4X:
MySQLConnection.Initialize("http://webservices.mymanager.gr/mysqltunnel.php", "127.0.0.1", "3306", "qualisys_demodb", "qualisys_demodb", "12345!@#$%", "utf8", True, "")

or edit the default mysql port in you server's php.ini
 

peacemaker

Expert
Licensed User
Longtime User
Thanks, aalekizoglou.
But found that only Debug-version of app is working. If to compile the release (obfuscated) - just progress-bar (release without obfuscation is OK !).
It's due to CallSub in your classes that use the sub name as variable...ohh, let's try to maybe fix...
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
DBMySQLConnection.ExecuteScript(sSQLParsed, "JobExecute_Done", "JobExecute_Failure", Me)
changes like this is needed, to be non-obfuscated
 

jiangws

Member
Licensed User
Longtime User
Hi aalekizoglou,

Thank for your reply.

"host=192.168.0.6&port=3306"->wrong
"host=127.0.0.1&port=3306"->Ok
"host=127.0.0.1->Ok
"host=localhost&port=3306"->OK
"host=localhost->OK

but it will be wrong if I install webserver and mysql server in differcent machine.


 

jiangws

Member
Licensed User
Longtime User
Hi peacemaker,

I changed to MEDIUMBLOB , It's OK.

Thank a lot of.
 

jiangws

Member
Licensed User
Longtime User
About null after save new record

Hi aalekizoglou,

The name and surname are "NULL" after I save new record.

I revised the function of OnAfterPost:

B4X:
Sub OnAfterPost(DBMySQLDataset As ClsDBMySQLDataset)
   lstView.Clear
   Dim Bookmars As typBookmark = MySQLDataset.GetBookmark

   ProgressDialogHide   
   MySQLDataset.Execute
   
'   MySQLDataset.FirstRecord
'   Do While Not(MySQLDataset.EOF) 
'      Dim tl As TwoLines      
'      tl.First = MySQLDataset.FieldByName("strLastName").GetValue
'      tl.Second = MySQLDataset.FieldByName("strFirstName").GetValue
'      lstView.AddTwoLines2(tl.First, tl.Second, tl)
'      MySQLDataset.NextRecord
'   Loop
'   
'   If Bookmars <> Null Then MySQLDataset.GotoBookmark(Bookmars)
   ToastMessageShow("Record saved succesfully." , False)
   edtContacts.Text = MySQLDataset.RecordCount
   
End Sub

It works, but I think it's not best method.



 

aalekizoglou

Member
Licensed User
Longtime User

There should be no problem on this. At least this is not a problem of the mysqltunnel.php.

Just make sure you can connect to remote mysql on 192.168.0.6 from the machine running Web server using the username and password provided.
If this works there should no problem on
"host=192.168.0.6&port=3306"->wrong
 

aalekizoglou

Member
Licensed User
Longtime User
changes like this is needed, to be non-obfuscated

peacemaker,

you are correct. Hadn't tried obfuscated before. What changes do we need to make that running in a obfuscated compilation?
 

peacemaker

Expert
Licensed User
Longtime User
Actually i had to made many changes in classes' sub names (adding "_"), but final requirement was "JobExecute_Done" and "JobExecute_Failure".

Some changes done and maybe no need:

 

aalekizoglou

Member
Licensed User
Longtime User
peacemaker,

OK. I saw that and made the changes too. I'll update the initial thread, too.

Thanks,
 

peacemaker

Expert
Licensed User
Longtime User
I'm digging a problem with
clsdbmysqldataset_updatebuffer (B4A line: 834)

Row = Dataset.Rows.Get(RecordNumber - 1)
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
if the first record is already existing...

Totally i have 14 fields, and no Boolean used !
But RecordNumber = 0 and index=-1

I cannot understand why Boolean is found, i use DATA, TEXT, INT MySQL fields...
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Seems,

'Initialize Record Pointer
RecordNumber = 0

is a mistake... i'm debugging with RecordNumber = 1...

And it's unclear - why INT field just after Posting is ftBOOLEAN in "UpdateRow".
 

aalekizoglou

Member
Licensed User
Longtime User
peacemaker,

I cannot understand your problem. The datatypes for various fields from MySQL are reported from the tunnel. If you check function GetCorrectDataType you'll see that it explicitly returns the field type as boolean if it is int(1). In fact MySQL's boolean is an alias for int(1), since there is no real boolean type in MySQL.

So if the tunnel connects through mysql protocol then this function is called. On the other hand if you use mysqli then function GetCorrectDataTypeMySQLI is used to get the correct types. There is no boolean field there and that might be a problem.

Can you clarify the problem you have, so that I can understand where the problem is?
 

peacemaker

Expert
Licensed User
Longtime User
Aha! That this int(1) is those problem !
I used it for my INT fields, it's enough.

Now changed to int(2) - and problem solved
Thanks for the info, better to add some warning text to the first your post about this - i guess most of B4A users starting with MySQL do not know such detailes that is hidden limit.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Found next problem.
If to change the SQL requests, i try to clear old:
MySQL_Dataset.SQL.Clear
MySQL_Dataset.SQLRefresh.Clear
MySQL_Dataset.SQLInsert.Clear
MySQL_Dataset.SQLUpdate.Clear

but get

clsdbmysqldataset_parseparameters (B4A line: 1361)
End Sub
java.lang.IndexOutOfBoundsException: Invalid index 8, size is 7

I mean - is it possible for the initialised MySQL_Dataset to change the SQL requests ?
How correctly ?

I just full re-init is required for each new SQL request ?
 
Last edited:

rg58sma

Member
Licensed User
Longtime User
I have the same


I have the sameeee
 

aalekizoglou

Member
Licensed User
Longtime User


I'll check on this. Think I know where the problem is. Will let you know.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…