B4A Library DataServer Library

Hello Every I Make My First Lbrary And Called DataServer I want To share it

I hope my first library help Every one here

Note:this library is work only with b4a v7.00+
  • LibraryName: DataServer
  • Library Auther :Azzam
  • How Data Server Work
    Data Server Created with All best Subs that make Execute Run Fast Like HandleJobAsync sub and other subs Also Data Server Can Use with All Data Types (sql server, mysql,...) ALSO You Can Hanlde many query in same times And Take Short time Because this data server Is Create every thing To you (Command,Dbrequest,parameters,Handlejob) also I Make some subs To Generate view like spinner and I when I Update it next time I will Add More Funcitons To It.

  • Initialize(Target as object,UrlLink as string,EventName as string)
    This Library Is used DBRequestResumable Class You must Before Use it Call this sub To Initialize it So You Don't Need To Add DBRequestResumable Class because its with it
    Target is the reference to the Activity Or Class who used this library
    UrlLink Is The link you Use it in DBRequestResumable for example 'http://192.168.1.100:17178/rdc'
    EventName Is the event name that will Used with All event for example 'Shop_TransactionComplete'

    B4X:
    Sub Globals
    Dim LocalServer as DataServer
    end sub
    
    
    [*]Sub Activity_Create(FirstTime As Boolean)
    if FirstTime then
    localserver.Initialize(Me,"http://192.168.1.100:17178/rdc","Shop")
    end if
    end sub
    sub Shop_TransactionComplete
    end sub

  • GenerateParameter(paramname As Object)
    this sub Is For Generate Params you can Call it multi times Or Create Array

    B4X:
    sub GetShopproducts(shopid as int)
    localserver.GenerateParameter(shopid)
    'Or use Array Of Parameters
    'localserver.GenerateParameter(array of object(shopid))
    end sub

    Note:You Must Call It Before Use Other sub Like GenrateTrasaction sub If you don't use it of pass Null as parameter the parameter will not Create If You Query Not have Any parameters you Ignore it Or pass Null To it

    B4X:
    sub GetAllProducts as list
    localserver.GenerateParameter(Null)
    'Or you can Ignore
    end sub
  • Public Sub GenerateMultiparameter(paramsname() As Object)
    This Sub Is For Generate multi array of Object And you must use it Only with sub that has 'Multi' keyword like GenerateMultiTransactions and ReturnMultiData

    B4X:
    sub UpdateMultishopsAndProducts(shopid as int,prodid as int)
    Localserver.GenerateMultiparameter(array(shopid,prodid))
    'OR you Can Add multi array
    'Localserver.GenerateMultiparameter(array(array(shopid),array(prodid))) 'Note :IF you use array with Generateparameter sub this will use it as single Parameter ,If you use it with this sub this will use every parameter as single For each Command
  • Public Sub Runtransaction(commandname As String)
    this sub will run query that not return value like update query and when it complete will fire the event 'TransactionComplete' But Notice that You must use Genrateparameter sub with it If the query has parameters
....Continue

the library will be in next post with example
 
Last edited:

azzam223

Active Member
Licensed User
Longtime User
Continue ....

when the Runtransaction sub the event TransactionComplete will file and return Result type paramter

The Result Type parameter Is the parameter to all event It's type object and Has two Properties
Success : Boolean type To check the event success or not
Res:Object type to include the error message when the sub is not success

Note:You have Two option To use it the first is with wait for OR without it

with wait for
B4X:
localserver.Runtransaction("GetAllCities")
wait for Eventname_TransactionComplete(Restype as result)

if restype.success then
'Code To Execute when success
else
msgbox(restype.res,"Test")

Or without wait for

B4X:
Sub eventname_TransactionComplete(restype as result)
if restype.success then
'Code to execute when its success
else
msgbox(restype.res,"Error")
end if

  • RunResumableTransaction(commandname As String) As ResumableSub

    this sub is like the above but using the ResumableSub Feature
    Note:
    the subs whose Have ResumableSub Feature Or Contains 'Resumable' will work only with B4a V7.30 And above Don't Forget that

    this sub will work with (wait for ) as example
    B4X:
    wait for (RunResumableTransaction("GetAllCities")) Complete(ResType as resutl)
    if restype.success then
    'code
    else
    msgbox(restype.res,"Error")
    end if

  • RunMultiTransactions(Commandsname() As String)
    this Sub Is used To Execut multi query For example update multi tables in same time You must array names Of command To run it
    Note:IF the any command have paramters you use the GenerateMultiparameter instead of GenerateParameter And Also If some command have parameter and some not you must put the command with parameter in the first And Also You must make it in the same order The event MultiTransactionComplete(Restype as result) will fire's when sub compelete
    B4X:
    dim lstparams as list
    lstparams.add(1)
    lstparams.add(3)
    lstparams.add(5)
    localserver.GenerateMultiparameter(lstparams)
    dim lstnames as list
    lstnames.add("Deleteproduct")
    lstnames.add("UpdateCategory")
    lstname.add("add Category")
    localserver.RunMultiTransactions(lstnames)
    wait for MultiTransactionComplete(restype as result)
    if restype.success then
    'done
    else
    msgbox(restype.res,"Error")

  • Returndata(commandname As String,limit As Int)
    this sub Is used To Run query that return Value
    Any query return data Even update or insert or delete query if you want it to return value then add the query that rerurn value after the insert query in procedure query I don't know If this work with config file or not

    when this return value then the event ResultDataComplete(restype as result) you can use it with wait for or without it like the sub above

  • ReturnResumabledata(commandname As String,limit As Int) as ResumableSub
    this sub is like the above sub but using ResumableSub Feature As I Tell in First This sub work only with b4a v7.30 and above you can use with Wait For

  • ReturnMultiData(commands() As String,multievent As Boolean),ReturnMultiResumableData(commands() As String) As ResumableSub
    this events like the above events Else when using ReturnMultiData and make multievent true when you make it true will not work wait For Because when the multievent paramter is true this will Call event ResultDataComplete multi times equal to commands number So you must use event in the default use like this
    B4X:
    sub ResultDataComplete(restype as result)
    
    end sub

    the events will fire with the order of commands If the parameter is False then the sub ResultMultiDataComplete(restype as list) will fire So You can Use it with Wait For Or without it
I am very sorry for late I will Make Full Exmaple To explain All fucntions in next post
 

Attachments

  • DataServer Library.zip
    32.9 KB · Views: 182
Last edited:

azzam223

Active Member
Licensed User
Longtime User
Hi Mashiane This library is use To make the rdc easy

this library use Rdc To connect To remote server And make this easy To every one Because Some user did know how the Rdc work Or now know How To wait For with it Or maybe Have problems with it I don't put this library to replace Rdc the Rdc Class Is Require To make all function of library work Because that I have include it
 
Last edited:

azzam223

Active Member
Licensed User
Longtime User
Any Suggestion Or problems with my library you put it here And I will try To Fix it in my next update
 

azzam223

Active Member
Licensed User
Longtime User
  • Generatespinner(spinner As Spinner,commandname As String,field name As String,valuename As String

    I am sorrt I forget explain last sub ,this sub is for fill spinner with data like combo box

    fieldname:the field name of disply value for exmaple To display Cities by it names we use 'Cityname'
    valuename:
    the value name to get value from combo box instead of index for example To get city data by it name we use the cityid value
    B4X:
    localserver.Generatespinner(spinCities,"GetAllCities","cityname","cityid")

    we can use it with wait for or without it ,when the complete the event GeneratedComplete will fire's
  • GetSpinnervalue(index As Int,spin As Spinner)As String
    this sub To get value from spinner selected index You can use multi spinner the sub will save values for every spinner

    B4X:
    sub LoadCities
    wait for (localserver.Generatespinner(spinCities,"GetAllCities","cityname","cityid")) GenerateComplete(restype as result)
    end sub
    
    Sub spinCities_ItemClick (Position As Int, Value As Object)
    dim value as int =localserver.GetSpinnervalue(position,spinCities )
    Localserver.GenerateParameter(value)
    localserver.Generatespinner(spinStreet,"GetCitystreets","Streetname","streetid")
    end sub
    Sub spinStreet_ItemClick (Position As Int, Value As Object)
    
    [*]dim value as int =localserver.GetSpinnervalue(position,spinStreet)
    Localserver.GenerateParameter(value)
    localserver.Generatespinner(SpinProds,"GetCitystreets","Streetname","streetid")
    end sub
    [*]

    Data Server Steps :
  1. Declare Variable with type Dataserver in General sub
    B4X:
    sub_Globals
    Public LocalServer as DataServer
    end sub
  2. Initialize the variable First time in activity Main Or in initialize sub in Class

    B4X:
    Public Sub Initialize
    localServer.Initialize(Me,"http://192.168.1.100:17178/rdc","Cities")
    End Sub
  3. Call GenerateParameter sub To add single parameter Or GenerateMultiparameter sub To Add mulit parameters TO mulit command names if the command not have any parameter there is no need To call it as I explain that in last post
    B4X:
    sub GetCityStreet(id as int)
    localsub.Generateparameter(id)
    end sub
  • Call sub Runtransaction,RuntResumableransaction to Execut single command RunMultiTransactions,RunMultiResumableTransactions To Execut Multi command this sub dose not return Any value
  • Call sub Returndata,ReturnResumabledata To Return single data command ..ReturnMultiData,ReturnMultiResumableData To return multi different data
  • Call sub Generatespinner to Fill Spinner with data And Call Getspinnervalue To return data
Any Questions Or suggestion I will Happy for that :)

Note: I will be Add Short post in the Updates libraries thread if there any update to library
 
Last edited:

azzam223

Active Member
Licensed User
Longtime User
every one want the library without dbreqmanager included replace the xml file with this one in the attachment but must he included in the project also must use the DBreqmanager with project
 

Attachments

  • DataServer.xml
    9 KB · Views: 155
Top