View Single Post
Old 11-06-2002, 13:10   #3
cionci
Senior Member
 
L'Avatar di cionci
 
Iscritto dal: Apr 2000
Cittā: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
Da quello che ho sperimentato io...i vari metodi di accesso ai database necessitano di una struttura ad oggetti...e questo implica che il C sia poco adatto ad utilizzarli...o meglio...non sono forniti gli strumenti adatti per utilizzarli...

Infatti...ADO ha una struttura intrinsecamente ad oggetti...MySQL ha delle librerie per il C++, suppongo quindi ad oggetti...

Comunque puoi sempre passare dalle chiamate dirette alle DLL di ODBC...quindi puoi supportare praticamente qualsiasi DB, basta che abbia un driver ODBC (anche MySQL ce l'ha)...

Le API per accedere in C ai DB tramite ODBC sono molte...
Questo sotto č un esempio :

Codice:
#define NAME_LEN 50
#define PHONE_LEN 50

SQLCHAR   szName[NAME_LEN], szPhone[PHONE_LEN];
SQLINTEGER  sCustID, cbName, cbAge, cbBirthday;
SQLRETURN retcode;
SQLHSTMT  hstmt;

retcode = SQLExecDirect(hstmt,
    "SELECT CUSTID, NAME, PHONE FROM CUSTOMERS ORDER BY 2, 1, 3",
    SQL_NTS);

if (retcode == SQL_SUCCESS) {
   while (TRUE) {
      retcode = SQLFetch(hstmt);
      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
         show_error();
      }
      if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){

         /* Get data for columns 1, 2, and 3 */

         SQLGetData(hstmt, 1, SQL_C_ULONG, &sCustID, 0, &cbCustID);
         SQLGetData(hstmt, 2, SQL_C_CHAR, szName, NAME_LEN, &cbName);
         SQLGetData(hstmt, 3, SQL_C_CHAR, szPhone, PHONE_LEN,
              &cbPhone);

         /* Print the row of data    */

         fprintf(out, "%-5d %-*s %*s", sCustID, NAME_LEN-1, szName, 
             PHONE_LEN-1, szPhone);
      } else {
         break;
      }
   }
cionci č offline   Rispondi citando il messaggio o parte di esso