ODBCDatabase

From Xojo Documentation
Jump to: navigation, search

Class (inherits from Database)

Used to open an ODBC database using an ODBC drivers. You use the constants in the ODBCConstant module with the methods and properties of the ODBCDatabase class.

Properties
Attribute Error ReadOnlyProperty.png Password
AttributeString ErrorCode ReadOnlyProperty.png ScrollableCursor
DBMS ReadOnlyProperty.png ErrorMessage ReadOnlyProperty.png Timeout
DataSource ExtendedSchema UserName
DatabaseName Host


Methods
Close GetInfo Rollback
ColumnPrivileges GetSQLTypeInfo SQLExecute
Commit IndexSchema SQLSelect
Connect InsertRecord SetConnectionAttribute
DataSourceNames NextRecordSet SpecialColumns
DriverNames Prepare TablePrivileges
FieldSchema PrimaryKeys TableSchema
ForeignKeys ProcedureColumns
GetConnectionAttribute Procedures


Notes

In order to use this class, you must have the ODBCDatabase plug-in in your plugins folder.

The ODBCDatabase class also requires a driver manager and driver. On the Windows platform, the driver manager is supplied by Microsoft as part of Windows or as part of the MDAC package. For non-Windows platforms, the iODBC driver manager is required, which is available from http://www.iodbc.org or is installed with most commercial drivers.

ODBC drivers may be included with the OS, or may be obtained from the database vendor or a commercial developer of ODBC drivers. Non-Windows drivers must be compatible with the iODBC standard. For macOS, Actual Technologies supplies iODBC compliant drivers that work well with Xojo apps. There are other vendors as well.

The ODBCDatabase engine supports all four RecordSet navigation methods: MoveFirst, MoveNext, MovePrevious, and MoveLast.

PostgreSQL Notes

On macOS, when connecting to PostgreSQL using ODBC you must specify a username and password. If you do not, the ODBC driver will crash your app.

Threading

SQLSelect and SQLExecute statements do not block when called from within Threads.

Examples

This example prompts the user to select a Data Source from either the User or System data sources:

Dim db As New ODBCDatabase
db.DataSource = ""
If db.Connect Then
// proceed with database operations
Else
MsgBox("Error: " + db.ErrorMessage)
End If

This example specifies a specific data source to use:

Dim db As New ODBCDatabase
db.DataSource = "TestAccessDB"
If db.Connect Then
// proceed with database operations
Else
MsgBox("Error: " + db.ErrorMessage)
End If

This example specifies the DSN information to connect to a Microsoft Access database:

Dim db As New ODBCDatabase
db.DataSource = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\TestAccessDB.mdb;Uid=Admin;Pwd=;"
If db.Connect Then
// proceed with database operations
Else
MsgBox("Error: " + db.ErrorMessage)
End If

See Also

Database Class, DatabaseField, DatabaseRecord, ODBCPreparedStatement, RecordSet classes.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About