Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/SQL/Web app/with SQLConnectionMBS
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/Web app/with SQLConnectionMBS
This example is the version from Thu, 6th Apr 2016.
Project "with SQLConnectionMBS.rbp"
Class App Inherits WebApplication
EventHandler Sub Open() call InternalSQLiteLibraryMBS.Use End EventHandler
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
Property db As SQLConnectionMBS
End Class
Class ConnectPage Inherits WebPage
Control Label1 Inherits WebLabel
ControlInstance Label1 Inherits WebLabel
End Control
Control Label2 Inherits WebLabel
ControlInstance Label2 Inherits WebLabel
End Control
Control Label3 Inherits WebLabel
ControlInstance Label3 Inherits WebLabel
End Control
Control Label4 Inherits WebLabel
ControlInstance Label4 Inherits WebLabel
End Control
Control PopupClient Inherits WebPopupMenu
ControlInstance PopupClient Inherits WebPopupMenu
EventHandler Sub Open() me.AddRow "DB2" Clients.Append SQLConnectionMBS.kDB2Client me.AddRow "Firebird" Clients.Append SQLConnectionMBS.kFirebirdClient me.AddRow "Informix" Clients.Append SQLConnectionMBS.kInformixClient me.AddRow "InterBase" Clients.Append SQLConnectionMBS.kInterBaseClient me.AddRow "MySQL" Clients.Append SQLConnectionMBS.kMySQLClient me.AddRow "ODBC" Clients.Append SQLConnectionMBS.kODBCClient me.AddRow "Oracle" Clients.Append SQLConnectionMBS.kOracleClient me.AddRow "PostgreSQL" Clients.Append SQLConnectionMBS.kPostgreSQLClient me.AddRow "SQLBase" Clients.Append SQLConnectionMBS.kSQLBaseClient me.AddRow "SQLite" Clients.Append SQLConnectionMBS.kSQLiteClient me.AddRow "SQLServer (Microsoft)" Clients.Append SQLConnectionMBS.kSQLServerClient me.AddRow "Sybase" Clients.Append SQLConnectionMBS.kSybaseClient End EventHandler
End Control
Control iDatabase Inherits WebTextField
ControlInstance iDatabase Inherits WebTextField
End Control
Control iUserName Inherits WebTextField
ControlInstance iUserName Inherits WebTextField
End Control
Control iPassword Inherits WebTextField
ControlInstance iPassword Inherits WebTextField
End Control
Control ConnectButton Inherits WebButton
ControlInstance ConnectButton Inherits WebButton
EventHandler Sub Action() if PopupClient.ListIndex<0 then MsgBox "Please select a client type." Return end if dim c as new SQLConnectionMBS // you can place the database client library files where you want. // example code just has some convenient location for testing. 'c.Option(c.kOptionLibrarySQLite) = "/usr/lib/libsqlite3.0.dylib" 'c.SetFileOption c.kOptionLibraryMySQL, SpecialFolder.UserHome.Child("libmysqlclient.dylib") 'c.SetFileOption c.kOptionLibraryPostgreSQL, GetFolderItem("libpq.dylib") dim client as integer = clients(PopupClient.ListIndex) if client <> SQLConnectionMBS.kSQLiteClient then MsgBox "We only allow here SQLite here." Return end if dim cDatabase as string = iDatabase.text dim cUsername as string = iUserName.text dim cPassword as string = iPassword.text c.Connect cDatabase, cUsername, cPassword, client Session.db = c SQLPage.show Exception s as runtimeexception MsgBox s.message End EventHandler
End Control
Control Label5 Inherits WebLabel
ControlInstance Label5 Inherits WebLabel
End Control
Property Clients() As Integer
End Class
Class SQLPage Inherits WebPage
Control List Inherits WebListBox
ControlInstance List Inherits WebListBox
End Control
Control QueryButton Inherits WebButton
ControlInstance QueryButton Inherits WebButton
EventHandler Sub Action() #pragma BreakOnExceptions false List.DeleteAllRows dim sql as string = iSQL.text dim co as new SQLCommandMBS co.setCommandText sql co.Connection = Session.db co.Execute List.ColumnCount = co.FieldCount dim c as integer = co.FieldCount-1 for x as integer = 1 to c dim field as SQLFieldMBS = co.field(x) List.Heading(x-1) = field.name next while co.fetchnext list.AddRow co.field(1).asStringValue for x as integer = 2 to c List.Cell(List.LastIndex, x) = co.field(x).asStringValue next wend Exception r as runtimeexception MsgBox r.message End EventHandler
End Control
Control iSQL Inherits WebTextField
ControlInstance iSQL Inherits WebTextField
End Control
Control Label1 Inherits WebLabel
ControlInstance Label1 Inherits WebLabel
End Control
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo Chart Plugins