B4A Library [Class] DBMySQL connect via MySQL Tunnel

aalekizoglou

Member
Licensed User
Longtime User
I have uploaded a new version in the first post
 

TomDuncan

Active Member
Licensed User
Longtime User
Hi.
With my xamp server this are ok but if I do a call to my website I get
Parse error: syntax error, unexpected '?' in /home/xxxx/public_html/mysqltunnel.php on line 527
I have a database setup and using on my web site. which I use with a Delphi 7 project.
Any thoughts.


Tom
 

aalekizoglou

Member
Licensed User
Longtime User
Nice to know there are other people working with Delphi here.

It seems there might be some libs missing in your server. Do you have access to Apache's errors.log and access.log? Can you debug to see what's wrong?

Definitely the problem would be on PHP's side with some libraries missing. I suppose you've got the latest mysqltunnel.php version from sourceforge.
 

TomDuncan

Active Member
Licensed User
Longtime User
Yep, through and through Delphi man.
Latest project used zeros. Good fun, now working ways to interface with android.
The server is from and company called siteground. They use cpanel as the interface.
I had to allow my tcpip address at home to get the zeos part to work.
They only error log I could find said eexactly what was in my last post.
Might have to go to a sqlite version which downloads the database on entry.
Not good but a the moment is all i can tthink of.

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
And yes latest everything.
Got them down this mmorning.
Pity though, loved the idea.

Tom
 

aalekizoglou

Member
Licensed User
Longtime User
Yes, it's a pity since I've written mysqltunnel to make things quick and simple. And on the other part B4A's dataset is used in a lot of project we have and is working fine.

For Delphi we've been working with UniDAC since 2007. Before that MyDAC was used.
Lately I've played a lot with CopyCAT for MySQL synchronization. Will try to incorporate that in our applications for off-line databases. For Android I've used sqlite for off-line but I lack Greek character functionality such as Searching.

I've planned to play with Delphi XE5 for android development as well.
Regards,
 

TomDuncan

Active Member
Licensed User
Longtime User
Might try again in the morning.
Then if that does not work, will use it for local work and then for doing a sqlite update.
This is a little app for my wife and i to log houses which we like on the australian realestate.com
we are selling our farm so b4a is an ideal platform to develop the software.

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
This morning put the tunnel php script in it's own folder.
At least now it is generating a log file.
Here are the last results.
MySQL Error = Access denied for user 'xxx'@'xxxxxxxx' (using password: YES)
I have tried with and without port.
either localhost or website address.
All with same results.
Somewhere within cPanel their must be a switch to allow access to the database.
This does however, work with my Delphi app using the same credentials.

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
Just changed the host part in the init to LocalHost and all works.
Great, now and can get started.

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
So far all is going well.
Have added
B4X:
    ExecutionType = 1
    MySQLDataset.Execute
    ProgressDialogShow("Please Wait")
  btnTake.Visible=False
End Sub

Sub OnAfter_Execute(DBMySQLDataset As ClsDBMySQLDataset)
    Select ExecutionType
        Case 1
            Dim i As Long
            AddressView.Clear

This will Update the correct Execution Type, say display a list of houses or select all for a selected house.
 

TomDuncan

Active Member
Licensed User
Longtime User
Thanks for your great addition.
I have finished the basic app. Looks good.
Will only be used for my wife and I at the moment.
I will test it outside my domain when I go to town next. (we do not have mobile reception at home)
and the Internet is via Satellite. (yuk and slow)

Tom
 

andre.astafieff

Member
Licensed User
Longtime User
Could anyone help me with this error?

B4X:
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=anywheresoftware.b4a.samples.camera/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
host=192.168.1.105&charset=utf8&dbname=cidades_br&username=bebi&password=bebi&query=%7B%22SQL%22%3A%22SELECT+*+from+cidades_br%22%2C%22params%22%3A%7B%7D%7D&compress=0
startService: class anywheresoftware.b4a.samples.httputils2.httputils2service
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Error occurred on line: 608 (clsdbmysqldataset)
java.lang.RuntimeException: JSON Object expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:47)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:858)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:823)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:232)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$3.run(BA.java:315)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5222)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
 

andre.astafieff

Member
Licensed User
Longtime User
I discovered the error.
I was trying to load a table with 21,886 records and 11 columns.
Was monitoring the variable mapResult sub JSONDecodeHeaders I realized the problem ...

B4X:
<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in <b>G:\xampp\htdocs\tunel\mysqltunnel.php</b> on line <b>371</b><br />

It would be a limitation of the database or application?
 

aalekizoglou

Member
Licensed User
Longtime User

Andres,

I would say this is an error coming from your PHP. You need to set php.ini to allocate more memory for scripts, if you wish to handle large dataset. You see the entire dataset must be loaded in memory, to generate the JSON resultset.

Thus I would be carefull with the phone's memory as well, case the exact resultset must be loaded in memory of the phone.

Regards,
 

KSC

Member
Licensed User
Longtime User
Installed project and get mysql syntax error on update of row with a photo included. 1st add of row with phot works fine, made photo column medium blob per previous remarks. MySql error pops up when updating the notes field after a photo is already in row. Appears encode/decode with encrption appears amiss. Can you confirm? response time to remote db is good without photo included. when included save message does not appear until up to 10 seconds. Is saving photo in db the best approach?
 

aalekizoglou

Member
Licensed User
Longtime User

KSC, With regards to the syntax error, I have to check what's wrong and let you know. To tell you the truth, it's been a long time since I last made changes to the library as I haven't found any problems working with it.

Saving a photo into the DB means having to transfer over the amount of Bytes (KB or maybe MB) to the remote server. Restoring back the field with the photo means getting that amount of Bytes back from the remote. Even though the library supports compression (you can try that as well), there will be a CPU overhead to the android device when preparing the blob data for sending over, which means some delay.

On the other hand some seconds delay when storing a blob field might not be as bad as it sounds considering you are saving a picture You might want to try resizing the picture to lower dimensions before saving it. If you are saving an 5MPixels or 8Mpixel image then the amount of data would be some megabytes in JPG format?
 

KSC

Member
Licensed User
Longtime User
Further testing shows that the notes field below the photo is becoming corrupted as well. I see funny characters in it when the myusql syntax error appears. periods single quotes in the text seems to be breaking the encyption/compression. The field is defined as text in the db. Does it require some type of escape function on special characters when storing? The photo is hit or miss on storage and retrieval. How do I select a photo? It always takes a picture when I click on the camera icon and do not see a control to select a smaller picture as you suggest.
 

KSC

Member
Licensed User
Longtime User
Is it possible to get support on this sample project? I have found 2 things wrong. The Notes field (which is defined as 'Text' in the database) is not base64 encoding and decoding correctly. I see that db field type of 'text' was not defined in the global definitions and case logic was not there either. If I switched the field to varchar(1000) then it works correctly with special characters (like apostrophes, backslashes etc) are escaped correctly. The second problem is the base64 encode and decode of the photos is not working on a retrieval from the database. Snapshots are uploaded to the database, supposedly base64 encoded. Yet on the retrieval from the database debug shows it is exceptioning within the 'initalize2' method and never retrieves the photo. When you change orientation from portrait to landscape you will see the photo is lost and cannot be retrieved. From threads I have seen on images stored as blobs, assumption is the photo has not be encoded/decoded correctly. I am running the latest Android Kitkat 4.4.2 using adt/sdk api 19 under dalvik. (Nexus 5). A reply would be appreciated.
 

aalekizoglou

Member
Licensed User
Longtime User

KSC, I'll have to check on those two problems and give you feedback. Is it a sample project you have or are you building a production app? What is the timeframe we have to check and find the problem?

Do you have a schema and B4A sample project with the libraries that you can share with me?
 

aalekizoglou

Member
Licensed User
Longtime User
Well, it seems I found the problem for TEXT field. Further investigation will help me find the problem with BLOBs as well. I'll try to fix that.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…