Platforms to show: All Mac Windows Linux Cross-Platform

/SQL/SQLDatabaseMBS Microsoft SQL cross platform


Required plugins for this example: MBS SQL Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/SQLDatabaseMBS Microsoft SQL cross platform

This example is the version from Fri, 23th Apr 2020.

Project "SQLDatabaseMBS Microsoft SQL cross platform.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Dim db As SQLDatabaseMBS = Connect // continue here with db If db <> Nil Then Dim r As RecordSet = db.SQLSelect("SELECT @@VERSION AS Version ") If r = Nil Then // error MsgBox db.ErrorMessage Else MsgBox r.IdxField(1).StringValue End If End If End EventHandler
EventHandler Sub Open() if TargetLinux then me.Height = 24 end if End EventHandler
End Control
Control iServer Inherits TextField
ControlInstance iServer Inherits TextField
End Control
Control iPort Inherits TextField
ControlInstance iPort Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control iUser Inherits TextField
ControlInstance iUser Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control iPass Inherits TextField
ControlInstance iPass Inherits TextField
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control iDatabaseName Inherits TextField
ControlInstance iDatabaseName Inherits TextField
End Control
Function Connect() As SQLDatabaseMBS // connect to Microsoft SQL Database Dim con As New SQLDatabaseMBS dim cs as string dim user as string = iUser.Text dim pass as string = iPass.Text dim databaseName as string = iDatabaseName.text dim server as string = iServer.text dim Port as string = iPort.Text #if TargetLinux then // install package tdsodbc cs = "DRIVER={libtdsodbc.so};Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port con.DatabaseName = "ODBC:"+cs con.Option("UseAPI") = "ODBC" #elseif TargetWin32 then cs = Server + "@"+DatabaseName con.UserName = User con.Password = Pass con.Option("OLEDBProvider") = "SQLNCLI" con.DatabaseName = "SQLServer:"+cs #elseif TargetMacOS then // download library on MBS website: // http://monkeybreadsoftware.de/xojo/download/plugin/Libs/ // connect via iODBC pointing to libtdsodbc (FreeTDS) Dim libtdsodbc As Folderitem = FindFile("libtdsodbc.dylib") cs = "DRIVER=" + libtdsodbc.NativePath + _ ";Server="+Server+";UId="+User+";PWD="+Pass+";Database="+DatabaseName+";TDS_VERSION=7.2;Port="+Port con.Option("UseAPI") = "ODBC" con.DatabaseName = "ODBC:"+cs #else ? #endif // DB Library settings con.Option("DBPROP_INIT_TIMEOUT") = "10" con.Option("DBPROP_COMMANDTIMEOUT") = "10" // ODBC settings con.Option("SQL_ATTR_QUERY_TIMEOUT") = "10" con.Option("SQL_ATTR_CONNECTION_TIMEOUT") = "10" if con.ConnectMT then con.Scrollable = True // if you like to get exceptions instead of checking error property con.RaiseExceptions = false return con Else dim e as string = con.errorMessage System.DebugLog e Break end if End Function
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

The items on this page are in the following plugins: MBS SQL Plugin.


The biggest plugin in space...