dart_odbc 1.1.1+2
dart_odbc: ^1.1.1+2 copied to clipboard
A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.
dart_odbc #
A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.
This package is inspired by the obsolete odbc package by Juan Mellado.
Usage #
- Instanciate the ODBC class by providing the path to the odbc driver on the host machine
final odbc = DartOdbc(
'/path/to/the/odbc/driver',
version=SQL_OV_ODBC3_80 // optional
);
Path to ODBC Driver #
Path to the ODBC driver can be found in the ODBC driver manager.
In windows this is a .dll file that is there in the installation folder of the ODBC driver.
In linux this has an extension of .so.
In macos this should have an extension of .dylib.
version #
The ODBC version can be specified using the version parameter.
Definitions for these values can be found in the LibODBC class.
Please note that some drivers may not work properly with manually setting version.
- Connect to the database by providing the DSN (Data Source Name) configured in the ODBC Driver Manager
odbc.connect(
dsn: '<your_dsn>',
username: 'db_username',
password: 'db_password',
);
DSN (Data Source Name) #
This is the name you gave when setting up the driver manager. For more information, visit this page from the MySQL Documentation
- In case the path privided to the driver is invalid or there is any issue with setting up the environment/connecting to the database, an
Exceptionwill be thrown when intanciating the ODBC or connecting to the database. - Execute your queries directly as follows
final result = odbc.execute("SELECT 10");
Executing prepared statements #
- Prepared statements can be used to prevent
SQL Injection - Example query
final List<Map<String, dynamic>> result = odbc.execute(
'SELECT * FROM USERS WHERE UID = ?',
params: [1],
);
- Result will be a
ListofMapobjects where each Map represents a row. If anything goes wrong anODBCExceptionwill be thrown
Accessing ODBC diver directly #
-
Native
ODBCmethods can be executed by using theLibODBCimport -
For more information on the
ODBCapi go to Microsoft ODBC Documentation
Tested On #
This package has been tested to be working on the following Database Servers
- Microsoft SQL Sever
- Oracle
Support for other Database Servers #
- Although not tested, this plugin should work on any database that provides an
ODBC Driver. - For a comprehensive list of supported database servers checkout
Driverssection of the official unixodbc site