Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 338596 Details for
Bug 447288
=dev-db/sqlncli-11.0.1790.0 - New package. - Microsoft® SQL Server® ODBC Driver 1.0 for Linux
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
A simple example program for testing sqlncli via unixODBC
sqlncli-msdn-odbc-example.c (text/plain), 3.36 KB, created by
Hugo Mildenberger
on 2013-02-11 14:15:19 UTC
(
hide
)
Description:
A simple example program for testing sqlncli via unixODBC
Filename:
MIME Type:
Creator:
Hugo Mildenberger
Created:
2013-02-11 14:15:19 UTC
Size:
3.36 KB
patch
obsolete
>/** > * Sourced from Microsoft sqlblog: > * http://blogs.msdn.com/b/sqlblog/archive/2012/01/26/use-existing-msdn-c-odbc-samples-for-microsoft-linux-odbc-driver.aspx > * > * Original title: > * Use Existing MSDN C++ ODBC Samples for Microsoft Linux ODBC Driver > * By Gregory Suarez | Sr. Escalation Engineer | SQL Server > * > * > * Slightly adapted: > * - loop initial declarations are only allowed in C99 mode > * > * Compile and link this program using: > * gcc sqlncli-msdn-odbc-example.c -o sqlncli-msdn-odbc-example -lodbc > * >**/ >#include <stdio.h> >#include <stdlib.h> >#include <sqlext.h> >#include <sql.h> > >#define NAME_LEN 50 >#define PHONE_LEN 20 > >void show_error() { > printf("error\n"); >} > >int main() { > SQLHENV henv; > SQLHDBC hdbc; > SQLHSTMT hstmt = 0; > SQLRETURN retcode; > SQLCHAR szName[NAME_LEN], szPhone[PHONE_LEN], sCustID[NAME_LEN]; > SQLLEN cbName = 0, cbCustID = 0, cbPhone = 0; > > // Allocate environment handle > retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); > > // Set the ODBC version environment attribute > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0); > > // Allocate connection handle > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); > > // Set login timeout to 5 seconds > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0); > > // Connect to data source > retcode = SQLConnect(hdbc, (SQLCHAR*) "SQLCMD", SQL_NTS, (SQLCHAR*) "Test1", 5, (SQLCHAR*) "Password1", 9); > > // Allocate statement handle > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); > > retcode = SQLExecDirect (hstmt, (SQLCHAR *) "SELECT CustomerID, ContactName, Phone FROM CUSTOMERS ORDER BY 2, 1, 3", SQL_NTS); > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > > // Bind columns 1, 2, and 3 > retcode = SQLBindCol(hstmt, 1, SQL_C_CHAR, sCustID, 100, &cbCustID); > retcode = SQLBindCol(hstmt, 2, SQL_C_CHAR, szName, NAME_LEN, &cbName); > retcode = SQLBindCol(hstmt, 3, SQL_C_CHAR, szPhone, PHONE_LEN, &cbPhone); > > // Fetch and print each row of data. On an error, display a message and exit. > int i; > for (i=0 ; ; i++) { > retcode = SQLFetch(hstmt); > if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) > show_error(); > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) > printf( "%d: %s %s %s\n", i + 1, sCustID, szName, szPhone); > else > break; > } > } > > // Process data > if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { > SQLCancel(hstmt); > SQLFreeHandle(SQL_HANDLE_STMT, hstmt); > } > > SQLDisconnect(hdbc); > } > > SQLFreeHandle(SQL_HANDLE_DBC, hdbc); > } > } > SQLFreeHandle(SQL_HANDLE_ENV, henv); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 447288
:
332322
|
332324
|
332326
|
338588
|
338590
|
338594
| 338596 |
338598
|
338600
|
338642
|
338684