[chargeable] MSMySQL - Yet another MySQL-Library (but a FAST one :-))

DonManfred

Expert
Licensed User
Longtime User

tamayo461

Member
Licensed User
Longtime User
You cant catch them... Write queries which dont raise an exception.

thank you DonManfred, I was watching the ne profile publications and are really amazing, and I plan to take a long time to explore, I do not have much experience developing for android, but I really want to learn, thanks again.
 

MohammadNew

Active Member
Licensed User
Longtime User
Hello

how to change this code to working on mysql localhost

db.Initialize("MySQL","localhost:3306","user","pass","database",True,True)

does not work

Thanks
 

Zeljko Gombovic

Member
Licensed User
Longtime User
Sub Globals
Dim db As MySQL
Private lv1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
db.Initialize("MySQL","xxx.xxx.xxx.xxx","user","password","database",False,False)
End Sub

Sub Activity_Resume
db.ListTablesAsync
End Sub

Sub MySQL_ListTables(tables As List, ms As Long)
For i=0 To tables.Size-1
lv1.AddSingleLine(tables.Get(i))
Next
End Sub

********************************************************************
Error occurred
An error has occurred in sub:
java.lang.Exception: Sub mysql_listtables signature does not match expected signature.
Continue?
********************************************************************

I just wanted to connect to the database and to echo the table , however, is the result of an error , in which I'm wrong ?
 

vbmundo

Well-Known Member
Licensed User
Hi,

I read that you said that this control does not handle SQL errors .. that makes me NockOut because in my application users write their own SQLs

If I put the SQL stattement into a Try Catch structure, can Cach the Error ? or application definitely explode?

Thanks
 

vbmundo

Well-Known Member
Licensed User
I'm using another MySQL/MariaDB Control

I test both with the same Query...

My Old MySQL Control : 7 Sec
Your MySQL Control : 2 Sec

WOW

I'm impressed
 

vbmundo

Well-Known Member
Licensed User
Hi,

I have this error

B4X:
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap

the original code is this

B4X:
Sub ArmoPantallaTablas
    Telefono.SetScreenOrientation(1)
    g.Initialize(Me,"g")
    g.InitializeTable(2,0,False)
    g.AddToActivity(Activity, 0, 54dip, 100%x, 80%y)   
    g.SetHeader(Array As String("Table Name", "Rows"))
    g.SetColumnsWidths(Array As Int(80%x, 20%x))
   
    ' Leo los registros
   
    Indice=1
    Maximo=0

    BotonQuery.Enabled=False
   
       ProgressDialogShow("Reading Tables")
    Starter.Dbn.QueryASync2("SELECT TABLE_NAME, TABLE_ROWS, TABLE_SCHEMA FROM TABLES WHERE TABLE_TYPE='BASE TABLE' ORDER BY TABLE_NAME","ListaTablas")

    BotonStructures.Enabled=False
   
    Activity.AddMenuItem("Jump Next 15", "Jump1")
    Activity.AddMenuItem("Jump To 0", "Jump2")
End Sub

Sub ListaTablas_QueryResult2(data As List, meta As Map)
    Dim m As Map
    Maximo=Maximo+1
    Log("MySQL_QueryResult("&meta&")")
    For i=0 To data.Size-1
        m=data.Get(i)
        If i = 0 Then Starter.BaseSeleccionada=m.Get("TABLE_SCHEMA")
        g.AddRow(Array As String(m.Get("TABLE_NAME"),m.Get("TABLE_ROWS")))
    Next 
    ProgressDialogHide
    BotonQuery.Enabled=True
    Activity.Title=" Tables of " & Starter.BaseSeleccionada
End Sub

This line throw error

B4X:
        g.AddRow(Array As String(m.Get("TABLE_NAME"),m.Get("TABLE_ROWS")))

What's wrong ?

Regards
 

DonManfred

Expert
Licensed User
Longtime User
QueryASync2
/**
* Query the Database. When the Method finishes the event QueryResult2
* will be raised
* QueryResult gets two values. A "List of Strings" for the results. Each
* Item in the List contains a String holding the Values from on Resultrow
* in the format "["+field1+","+field2+"]"
*
* The Second value is a Map containing some informations:
* ColumnCount, RecordCount and time elapsed in ms for the query
*Example:<code>
*db.queryasync2("select * from members LIMIT 0,1 ;")</code>
*/

You should use QueryAsync if you want to get a list of maps.
 

vbmundo

Well-Known Member
Licensed User
Hi,

I see some problems or doubts with this control

1. The TASK parameter in QueryASync doesn't work... I use the Task "MySQL" in Initialize and "ReadTables" in the QueryAsync. Only can catch the MySQL_QueryResult but not ReadTables_QueryResult

B4X:
        Starter.Dbn.Initialize("MySQL",Starter.MySQL_Server&":"&Starter.MySQL_Port,"information_schema",Starter.MySQL_User,Starter.MySQL_Password,True,True)

B4X:
            Starter.Dbn.QueryASync("SELECT DISTINCT(TABLE_SCHEMA) AS BASE, Count(DISTINCT(TABLE_SCHEMA)) as Registros FROM TABLES WHERE TABLE_SCHEMA<>'information_schema'","VerTablas")

Only this event works.

B4X:
Sub MySQL_QueryResult(data As List, meta As Map)
    Dim m As Map
    CantidadBases=0
    For i = 0 To data.Size-1
        CantidadBases=CantidadBases+1
        m=data.Get(i)
        Starter.ListadeBases.Add(m.Get("TABLE_SCHEMA"))
    Next
    If data.size=1 Then StartActivity(ListaTablas)
    If data.Size>1 Then StartActivity(Databases)
End Sub

2. This line stop the APP without any log error

B4X:
    For i = 0 To data.Size-1

3. I don't see any "Query_Error" you assume that all instructions run perfectly without errors. You have not provided a fault handler.

I thinks that your control or App is THE BEST.. but the Keirs user, have 2 o 3 interesting diferences.. you can run severals SQL queries and manage every one in different SUBS (one for every task)

And he has included a xxxx_error(status as string) event. And your APP not crash.. you can manage the error.

I hope that you can help me with me errors..

Regards
 

DonManfred

Expert
Licensed User
Longtime User
Why the PORT parameter is not included in the Connection Parameters ?
add the port to the host if you need a different on than 3306 (somedomain.tld:3333)

but not ReadTables_QueryResult
The method to get a tablelist is

B4X:
db.ListTablesAsync()
and it results in raising
B4X:
Sub MySQL_ListTables(tables As List, ms As Long)
    Log("MySQL_ListTables("&ms&"ms)")
    For i=0 To tables.Size-1
        Log("Table "&tables.Get(i))
    Next
End Sub
 

vbmundo

Well-Known Member
Licensed User
The method to get a tablelist is

B4X:
db.ListTablesAsync()
and it results in raising
B4X:
Sub MySQL_ListTables(tables As List, ms As Long)
    Log("MySQL_ListTables("&ms&"ms)")
    For i=0 To tables.Size-1
        Log("Table "&tables.Get(i))
    Next
End Sub

Hi Sorry, but if you see my SELECT statement , I have conditions and DISTINCT in my SELECT... is not a simply LIST TABLES statement.

And I need to fix the TASK issue... why including a TASK into the QUERYASync this doesn't work ?

Regards
 

vbmundo

Well-Known Member
Licensed User
Hi DonManfred,

What about the TASK label ? the TASK in the QUERYASYNC doesn't work..

I can't create one DB object for every SQL stattement, is not logical..

Regards
 

vbmundo

Well-Known Member
Licensed User
Hi,

I have this code

B4X:
        If data.Get("COLLATION_NAME")<>Null Then
           Cola=data.Get("COLLATION_NAME")
        Else
           Cola=""
        End If

And trow this error

B4X:
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
MySQL Database not connected!
Sub NOT FOUND: 'vertablas_status
Connected to Database
** Activity (main) Pause, UserClosed = false **
** Activity (listatablas) Create, isFirst = true **
** Activity (listatablas) Resume **
** Activity (listatablas) Pause, UserClosed = false **
** Activity (estructuras) Create, isFirst = true **
** Activity (estructuras) Resume **
An error occurred:
(Line: 72) If data.Get("COLUMN_DEFAULT")<>Null Then
java.lang.NumberFormatException: For input string: "COLUMN_DEFAULT"
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 
Top