0 branches
Tree
Top files
Clone with HTTPS:
README.md
db: fix V support to Microsoft SQL Server or to ODBC connection (fixes #4531)
last Apr 23
3.01 KB
_cdef_windows.c.v
vlib: move the mysql/sqlite/pg/mssql modules under vlib/db (#16820)
3 years ago
416 bytes
_cdefs.c.v
fmt: implement wrapping function's super long arguments (fix #15545, fix #21643) (#21782)
1 year ago
1.77 KB
mssql_test.v
db: fix V support to Microsoft SQL Server or to ODBC connection (fixes #4531)
last Apr 23
3.16 KB
result.v
db: fix V support to Microsoft SQL Server or to ODBC connection (fixes #4531)
last Apr 23
377 bytes
stmt_handle.c.v
db.mssql: fix builder error when db.mssql is imported (fixes #19141)
last Apr 14
4.25 KB
SQL Server ODBC
- This module wraps the ODBC C API for use with SQL Server.
- It can also be used with any ODBC data source by passing a raw ODBC connection string.
Scope
db.mssqlcan connect to any ODBC data source whenmssql.open(...)orConnection.connect(...)receives a valid ODBC connection string.Configcan build connection strings fromdriver,server,port,uid/user,pwd/password,dbname,dsn, and extra ODBC options.- For non-MSSQL ODBC sources, pass a DSN or raw ODBC string directly.
Dependencies
- ODBC driver manager development headers/libraries (
sql.h,sqlext.h).- Linux:
- Install unixODBC development packages (
unixodbc,unixodbc-dev, or distro equivalent).
- Install unixODBC development packages (
- macOS:
- Recommended: install unixODBC + pkg-config:
brew install unixodbc pkg-config - Then install your DB vendor ODBC driver (for SQL Server:
msodbcsql18). - Details: see the Microsoft SQL Server ODBC driver installation guide.
- Recommended: install unixODBC + pkg-config:
- Windows:
odbc32is included with the Windows SDK on most systems.- Details: https://learn.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server
- Linux:
Windows Notes
Using msvc
- Make sure
cl.exeofmsvcis accessible from command line. You can runvcommands inVisual Studio 2019 Developer Command Promptto be safe. - C Headers and dlls can be automatically resolved by
msvc.
Using tcc
- Copy those headers to
@VEXEROOT\thirdparty\mssql\include. The version number10.0.18362.0might differ on your system. Command Prompt commands:copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sql.h" thirdparty\mssql\include copy ^ "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqlext.h" ^ thirdparty\mssql\include copy ^ "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqltypes.h" ^ thirdparty\mssql\include copy ^ "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqlucode.h" ^ thirdparty\mssql\include copy ^ "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\sal.h" ^ thirdparty\mssql\include copy ^ "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\concurrencysal.h" ^ thirdparty\mssql\include - dlls can be automatically resolved by
tcc
TODO
- Support ORM
Usage
import db.mssql
fn test_example() ? {
// connect to server
mut conn := mssql.connect(
driver: 'ODBC Driver 18 for SQL Server'
server: '127.0.0.1'
port: 1433
user: ''
password: ''
dbname: 'master'
options: {
'Encrypt': 'yes'
'TrustServerCertificate': 'yes'
}
)?
defer {
conn.close()
}
// get current db name
mut query := 'SELECT DB_NAME()'
mut res := conn.query(query)?
assert res == mssql.Result{
rows: [mssql.Row{
vals: ['master']
}]
num_rows_affected: -1
}
}
You can also connect with a raw DSN or ODBC string:
mut conn := mssql.open('DSN=Reporting;Trusted_Connection=Yes')?