B4A Class sqlclass Fast Sql string generation from simple class to Mysql,Sqlite

Hello, every one

I share them the Fast Sql string generation from simple sqlclass

Sqlclass:
    ' insert example Mysql,Sqlite'
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","name text")
    Sqlcla1.AddColString("Doc","doc text")
    Sqlcla1.AddColString("Grado",1)
    Sqlcla1.AddColString("FechaIngreso","2021-02-21")
    Sqlcla1.AddColString("Edad",12)
    Sqlcla1.AddColString("Telefono", "+573014677797" )
    
    Dim sql As String = Sqlcla1.GetInsertQuery ' Sql para insertar datos
    ' generate string'
    ' sql = "Insert Into Estudiantes (NombreApellido,Doc,Grado,FechaIngreso,Edad,Telefono) Values  ('name text','doc text','1','2021-02-21','12','+573014677797');"'
    
    ' Select Query mysql,sqlite'
    Dim Sqlcla1 As Sqlclass   
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","")
    Sqlcla1.AddColString("Doc","")
    Sqlcla1.AddColString("Grado",1)
    Sqlcla1.AddColString("FechaIngreso","")
    Sqlcla1.AddColString("Edad",0)
    Sqlcla1.AddColString("Telefono", "" )   
    '------------- where condtion
    Sqlcla1.AddColIndex("Idestudiante", 23 )
    Dim sql As String = Sqlcla1.GetSelectQuery ' Sql generation
    'sql="Select   NombreApellido,Doc,Grado,FechaIngreso,Edad,Telefono  From Estudiantes Where Idestudiante='23'"'
    
    'update example Mysql,Sqlite'
    Dim Sqlcla1 As Sqlclass   
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","name text")
    Sqlcla1.AddColString("Doc","doc text")
    Sqlcla1.AddColString("Grado",1)
    Sqlcla1.AddColString("FechaIngreso","2021-02-21")
    Sqlcla1.AddColString("Edad",12)
    Sqlcla1.AddColString("Telefono", "+573014677797" )
    '------------- update col index
    Sqlcla1.AddColIndex("Idestudiante", 23 )
    
    Dim sql As String = Sqlcla1.GetUpdateQuery ' Sql get
    'sql="Update  Estudiantes Set NombreApellido='name text',Doc='doc text',Grado='1',FechaIngreso='2021-02-21',Edad='12',Telefono='+573014677797' Where Idestudiante='23'; "'
    
    ' Delete Query example Mysql,Sqlite'
        Dim Sqlcla1 As Sqlclass   
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","name text")
        '------------- update col index
    Sqlcla1.AddColIndex("Idestudiante", 23 )
    Dim sql As String = Sqlcla1.GetDeleteQuery
    'sql="Delete From  Estudiantes Where Idestudiante='23';"'
    
    ' example Insert Replace Query Sqlite'
    Dim Sqlcla1 As Sqlclass   
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","name text")
    Sqlcla1.AddColString("Doc","doc text")
    Sqlcla1.AddColString("Grado",1)
    Sqlcla1.AddColString("FechaIngreso","2021-02-21")
    Sqlcla1.AddColString("Edad",12)
    Sqlcla1.AddColString("Telefono", "+573014677797" )
        
    Dim sql As String = Sqlcla1.GetInsertReplaceQuery ' Sql para insertar datos
    
    'sql="Insert OR REPLACE INTO Estudiantes (NombreApellido,Doc,Grado,FechaIngreso,Edad,Telefono) Values  ('name text','doc text','1','2021-02-21','12','+573014677797');"'

   ' Insert update query Mysql
Dim Sqlcla1 As Sqlclass
    Sqlcla1.Initialize("Estudiantes")
    Sqlcla1.AddColString("NombreApellido","name text")
    Sqlcla1.AddColString("Doc","doc text")
    Sqlcla1.AddColString("Grado",1)
    Sqlcla1.AddColString("FechaIngreso","2021-02-21")
    Sqlcla1.AddColString("Edad",12)
    Sqlcla1.AddColString("Telefono", "+573014677797" ) 
    
    Dim sql As String = Sqlcla1.GetInsertUpdateQuery ' Sql generation
  'sql="Insert Into Estudiantes (NombreApellido,Doc,Grado,FechaIngreso,Edad,Telefono) Values  ('name text','doc text','1','2021-02-21','12','+573014677797') ON DUPLICATE KEY UPDATE NombreApellido='name text',Doc='doc text',Grado='1',FechaIngreso='2021-02-21',Edad='12',Telefono='+573014677797' ;"


 ' Ing. Fabio Vega  Colombia..
 

Attachments

  • Sqlclass.bas
    5.9 KB · Views: 165

Fabio vega

Member
Licensed User
The idea is easy and fast query generación for Many less error.
Ej, what query do You like to generarte?
 

Fabio vega

Member
Licensed User
1. Making non-parameterized queries is unacceptable in 2021...
2. Removing apostrophes from the inserted values is also unacceptable. Note that there are other characters that you need to escape.

The apostrophe is only necessary when the name of the column has spaces, but that is easy to request, to generate the Sql, I will add them.
and if it is due to the sql injection, this class does not allow, it generates a bad sql in such case.
But you're absolutely right
 
Last edited:
Top