Platforms to show: All Mac Windows Linux Cross-Platform
/SQL/Microsoft SQL via ODBC on Linux
Required plugins for this example: MBS SQL Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/Microsoft SQL via ODBC on Linux
This example is the version from Thu, 31th Jul 2019.
Project "Microsoft SQL via ODBC on Linux.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()
// preload libs, this helps on Linux to find them
dim libodbcinst as Folderitem = FindFile("libodbcinst.so.1")
dim libtdsodbc as Folderitem = FindFile("libtdsodbc.so")
dim s as new SoftDeclareMBS
call s.LoadLibrary(libodbcinst.nativePath)
call s.LoadLibrary(libtdsodbc.nativePath)
// connect
dim con as new SQLConnectionMBS
try
// we used Microsoft SQL Server 2008 and run app on Windows to test this
dim cs as string = "DRIVER={FREETDS};Server="+iServer.Text+";UId="+iUser.Text+";PWD="+iPass.Text+";Database="+iDatabaseName.Text+";TDS_VERSION=7.2;Port="+iPort.text
con.Option(con.kOptionLibraryODBC) = libtdsodbc.NativePath
con.Option("UseAPI") = "ODBC"
con.Connect(cs,"","",SQLConnectionMBS.kODBCClient)
con.Scrollable = false // disabling scrolling cursors is much faster for Microsoft SQL Server...
// add time stamp
dim cmd as new SQLCommandMBS(con, "insert into "+iTable.text+" ("+iColumn.text+") VALUES (SYSUTCDATETIME())")
cmd.Execute
// no commit as we have autocommit
MsgBox "Timestamp saved."
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect
catch r as RuntimeException
MsgBox r.message
end try
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
Control iColumn Inherits TextField
ControlInstance iColumn Inherits TextField
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control Label8 Inherits Label
ControlInstance Label8 Inherits Label
End Control
Control iTable Inherits TextField
ControlInstance iTable Inherits TextField
End Control
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.