Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/SQL/Web app/with SQLDatabaseMBS
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/Web app/with SQLDatabaseMBS
This example is the version from Thu, 6th Apr 2016.
Project "with SQLDatabaseMBS.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 SQLDatabaseMBS
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 "DB2" me.AddRow "Firebird" Clients.Append "Firebird" me.AddRow "Informix" Clients.Append "Informix" me.AddRow "InterBase" Clients.Append "InterBase" me.AddRow "MySQL" Clients.Append "MySQL" me.AddRow "ODBC" Clients.Append "ODBC" me.AddRow "Oracle" Clients.Append "Oracle" me.AddRow "PostgreSQL" Clients.Append "PostgreSQL" me.AddRow "SQLBase" Clients.Append "SQLBase" me.AddRow "SQLite" Clients.Append "SQLite" me.AddRow "SQLServer (Microsoft)" Clients.Append "SQLServer" me.AddRow "Sybase" Clients.Append "Sybase" 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 SQLDatabaseMBS // 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 string = clients(PopupClient.ListIndex) if client <> "SQLite" then MsgBox "We only allow here SQLite here." Return end if c.UserName = iUserName.Text c.Password = iPassword.Text c.DatabaseName = client+":"+iDatabase.Text if c.Connect then Session.db = c SQLPage.show else MsgBox "Failed to connect: "+c.ErrorMessage end if Exception s as runtimeexception MsgBox s.message End EventHandler
End Control
Control Label5 Inherits WebLabel
ControlInstance Label5 Inherits WebLabel
End Control
Property Clients() As string
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 r as RecordSet = Session.db.SQLSelect(sql) if Session.db.Error then MsgBox Session.db.ErrorMessage else List.ColumnCount = r.FieldCount dim c as integer = r.FieldCount-1 for x as integer = 1 to c dim field as DatabaseField = r.IdxField(x) List.Heading(x-1) = field.name next while not r.EOF list.AddRow r.IdxField(1).StringValue for x as integer = 2 to c List.Cell(List.LastIndex, x) = r.IdxField(x).StringValue next r.MoveNext wend end if Exception rr as runtimeexception MsgBox "Exception: "+rr.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.





Links
MBS Xojo Chart Plugins