Tam Sürümünü Görmek İçin : C ile MsSQL'e erişim?
Merhabalar,
mssql'e c dilinde erişim için örnek verebilir misiniz?
Bu konuda doküman aradım bulamadım, nereden bulabilirim?
acehreli
15/05/2006, 20:32
Google'da
mysql c api
diye aratinca ilk cikan sonuc:
http://dev.mysql.com/doc/refman/5.0/en/c.html
Oradan anlasildigina gore, ornek program arayanlar mysql'in icinde geldigi mysqlclient kutuphanesindeki 'client' programlarinin kodlarina bakabilirlermis.
Amaaa... :) Oraya birakilan bir mesaja bakilirsa artik client programlarin kodlari mysql'le gelmiyormus. :( Baska birisi de soyle bir ornek gostermis:
http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html
Ali
Sağol ama mssql için arıyorum.
http://www.ceviz.net/index.php?case=article&id=637&catid=13 burada olduğu gibi mssqli C'de kullanmak için standart APIler yok herhalde. sqllite diye bir API duymuştum bu işi yapan ama benim aradığım ekstradan bir şey gerekmeden direkt bağlanmak. ODBC yoluyla bu yapılabiliyormuş ama beceremedim. Yönetimsel araçlardan sql serverı ODBC'ye tanıttım. Sonra bulduğum kod örneklerini denedim, linker error veriyor .
#include <windows.h>
#include <sqlext.h>
#include <stdio.h>
int main(void)
{
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC hDBC = NULL; // Connection handle
HSTMT hStmt = NULL;
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "deneme"; // Data Source Name buffer
UCHAR* szUID = "kullanıcıadı"; // User ID buffer
UCHAR* szPasswd = NULL; // Password buffer
UCHAR szModel[128]; // Model buffer
SDWORD cbModel; // Model buffer bytes recieved
UCHAR szSqlStr[] = "Select name From Table1 Where id='1'";// SQL string
RETCODE retcode;// Return code
// Allocate memory for ODBC Environment handle
SQLAllocEnv (&hEnv);
// Allocate memory for the connection handle
SQLAllocConnect (hEnv, &hDBC);
// Connect to the data source "db97" using userid and password.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);
// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
// Execute the SQL statement handle
retcode = SQLExecute (hStmt);
// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
// Get row of data from the result set defined above in the statement
retcode = SQLFetch (hStmt);
while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
printf ("\t%s\n", szModel); // Print row (model)
retcode = SQLFetch (hStmt); // Fetch next row from result set
}
// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);
// Disconnect from datasource
SQLDisconnect (hDBC);
}
// Free the allocated connection handle
SQLFreeConnect (hDBC);
// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);
return 0;
}
bilen yok mu? :(
acehreli
17/05/2006, 19:11
Baglayicinin ne hatasi verdigini soylemedigin icin ancak tahmin edebiliyorum: programini, cagirmakta oldugun bir islevin taniminin icinde bulundugu kutuphane ile baglamiyorsun.
Ali
Forum Yazılımı : vBulletin v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.