15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Serializing Databases with ODBC....

Mihir Dalal -- m_dalal@ECE.concordia.CA
Friday, January 24, 1997


                   Environment: MSVC 1.52, Windows 95

Hi,

I have written the following as a part of a message handler responsible 
for serialzing data into a database file. 

  retcode = SQLAllocStmt(hdbc, &hstmt); 
  if (retcode == SQL_SUCCESS) 
   {
     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS);
     if (retcode == SQL_SUCCESS) 
      {
       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL);
       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL);
       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL);
       ...
       ...
       ...
       retcode = SQLExecute(hstmt);        
       if(retcode == SQL_ERROR)
        {
	   AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
	} 
       else
	{ 
         ...
         ...
        } 
       } 
     SQLFreeStmt(hstmt, SQL_DROP
   } 
  ...
  ...

My problem:
When I use SQLPrepare() to preapre the "INSER INTO..." statement followed 
by a couple of SQLSetParam()s followed by SQLExecute(), I always have to 
have my database table in the default directory which has been set while 
configuring the ODBC data source in question. 

Is there a way to dynamically resolve/alter the default directory in which
SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
attempts to serialize data ??

Any help appreciated.

Mihir. 
(Univeristy Researcher)



Vincent Mascart -- 100425.1337@compuserve.com
Sunday, January 26, 1997

>From: 	Mihir Dalal
>Sent: 	dimanche 26 janvier 1997 19:10
>To: 	INTERNET:MFC-L@NETCOM.COM
>Subject: 	Serializing Databases with ODBC....
>
>                   Environment: MSVC 1.52, Windows 95
>
>Hi,
>
>I have written the following as a part of a message handler responsible 
>for serialzing data into a database file. 
>
>  retcode = SQLAllocStmt(hdbc, &hstmt); 
>  if (retcode == SQL_SUCCESS) 
>   {
>     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS);
>     if (retcode == SQL_SUCCESS) 
>      {
>       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL);
>       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL);
>       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL);
>       ...
<       ...
>       ...
>       retcode = SQLExecute(hstmt);        
>       if(retcode == SQL_ERROR)
>        {
>	   AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
>	} 
>       else
>	{ 
>         ...
>         ...
>        } 
>       } 
>     SQLFreeStmt(hstmt, SQL_DROP
>   } 
>  ...
>  ...
>
>My problem:
>When I use SQLPrepare() to preapre the "INSER INTO..." statement followed 
>by a couple of SQLSetParam()s followed by SQLExecute(), I always have to 
>have my database table in the default directory which has been set while 
>configuring the ODBC data source in question. 
<
>Is there a way to dynamically resolve/alter the default directory in which
>SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
>attempts to serialize data ??
>
>Any help appreciated.

Hi Mihir,

You didn't specify with what kind of database you works. Since you speak about
directories, I suspect it is Access DB. Anyway, you can harcode the DB location
in your INSERT statement.

To see how, just start MSQuery, open an Access database and select some field.
The use the SQL button to view the generated SQL statement. You will see that
MSQuery use a full pathname to access the database.

You can use the same syntax in your INSERT statement, but you will lose some
portability ODBC provides.

If protability is a matter for you, you should use SQLGetInfo() to query the
ODBC driver about syntax of separators, qualifier, etc ... then construct your
INSERT statement programatically.

HTH

Vincent Mascart
100425.1337@compuserve.com




Mihir Dalal -- m_dalal@ECE.concordia.CA
Monday, January 27, 1997

[Mini-digest: 3 responses]

On 26 Jan 1997, Vincent Mascart wrote:

> >From: 	Mihir Dalal
> >Sent: 	dimanche 26 janvier 1997 19:10
> >To: 	INTERNET:MFC-L@NETCOM.COM
> >Subject: 	Serializing Databases with ODBC....
> >
> >                   Environment: MSVC 1.52, Windows 95
> >
> >Hi,
> >
> >I have written the following as a part of a message handler responsible 
> >for serialzing data into a database file. 
> >
> >  retcode = SQLAllocStmt(hdbc, &hstmt); 
> >  if (retcode == SQL_SUCCESS) 
> >   {
> >     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS);
> >     if (retcode == SQL_SUCCESS) 
> >      {
> >       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL);
> >       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL);
> >       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL);
> >       ...
> <       ...
> >       ...
> >       retcode = SQLExecute(hstmt);        
> >       if(retcode == SQL_ERROR)
> >        {
> >	   AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
> >	} 
> >       else
> >	{ 
> >         ...
> >         ...
> >        } 
> >       } 
> >     SQLFreeStmt(hstmt, SQL_DROP
> >   } 
> >  ...
> >  ...
> >
> >My problem:
> >When I use SQLPrepare() to preapre the "INSER INTO..." statement followed 
> >by a couple of SQLSetParam()s followed by SQLExecute(), I always have to 
> >have my database table in the default directory which has been set while 
> >configuring the ODBC data source in question. 
> <
> >Is there a way to dynamically resolve/alter the default directory in which
> >SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
> >attempts to serialize data ??
> >
> >Any help appreciated.
> 
> Hi Mihir,
> 
> You didn't specify with what kind of database you works. Since you speak about
> directories, I suspect it is Access DB. Anyway, you can harcode the DB location
> in your INSERT statement.
> 
> To see how, just start MSQuery, open an Access database and select some field.
> The use the SQL button to view the generated SQL statement. You will see that
> MSQuery use a full pathname to access the database.
> 
> You can use the same syntax in your INSERT statement, but you will lose some
> portability ODBC provides.
> 
> If protability is a matter for you, you should use SQLGetInfo() to query the
> ODBC driver about syntax of separators, qualifier, etc ... then construct your
> INSERT statement programatically.
> 
> HTH
> 
> Vincent Mascart
> 100425.1337@compuserve.com
> 

Hi Vincent,

Thanks for your response. I am sorry, I didn't mention what 
kind of databases, I am working with. Unfortunately, what you 
have suggested is not useful to me since I am working with dbase III 
tables. 

In any case, I am sure, dbase III will have some kind of utility 
which allows one to spy on the syntax of separators, qualifiers etc. 
of the generated SQL statements. 

I will try that and get back to you if I get into trouble.

Incidently, what I was looking for was some ODBC API that would allow 
me to alter the default directory setting. Isn't it surprising that ODBC 
does not offer such an API ??

Mihir.   
(University Researcher)

------------------ Dept. of Elec. & Comp. (ECE) Engg. --------------------

 Mihir Dalal                           phone : 1-514-274-4430
 M.Engg (Electrical) Student             fax : 1-514-421-1166
 Concordia University                 emails : m_dalal@ece.concordia.ca
 1455, De Maissoneuve Blvd.                      dalal@vlsi.concordia.ca
 Montreal QC CANADA H3G 1M8                    m_dalal@alcor.concordia.ca

----------- http://www.ece.concordia.ca/~m_dalal/addr.html ---------------

 
-----From: Lior Messinger <100274.2607@CompuServe.COM>

RE:	Copy of: RE: Serializing Databases with ODBC....

Mihir, 

You can also query the Registry. It's under ODBC, where the key names depend on
your driver settings and on your data source name, but usually it's under
HKEY_LOCAL_MACHINE::SOFTWARE\ODBC\ODBC.INI or
HKEY_CURRENT_USER::SOFTWARE\ODBC\ODBC.INI

Lior.
>From: 	Mihir Dalal
>Sent: 	dimanche 26 janvier 1997 19:10
>To: 	INTERNET:MFC-L@NETCOM.COM
>Subject: 	Serializing Databases with ODBC....
>
>                   Environment: MSVC 1.52, Windows 95
>
>Hi,
>
>I have written the following as a part of a message handler responsible 
>for serialzing data into a database file. 
>
>  retcode = SQLAllocStmt(hdbc, &hstmt); 
>  if (retcode == SQL_SUCCESS) 
>   {
>     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS);
>     if (retcode == SQL_SUCCESS) 
>      {
>       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL);
>       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL);
>       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL);
>       ...
<       ...
>       ...
>       retcode = SQLExecute(hstmt);        
>       if(retcode == SQL_ERROR)
>        {
>	   AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
>	} 
>       else
>	{ 
>         ...
>         ...
>        } 
>       } 
>     SQLFreeStmt(hstmt, SQL_DROP
>   } 
>  ...
>  ...
>
>My problem:
>When I use SQLPrepare() to preapre the "INSER INTO..." statement followed 
>by a couple of SQLSetParam()s followed by SQLExecute(), I always have to 
>have my database table in the default directory which has been set while 
>configuring the ODBC data source in question. 
<
>Is there a way to dynamically resolve/alter the default directory in which
>SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
>attempts to serialize data ??
>
>Any help appreciated.

Hi Mihir,

You didn't specify with what kind of database you works. Since you speak about
directories, I suspect it is Access DB. Anyway, you can harcode the DB location
in your INSERT statement.

To see how, just start MSQuery, open an Access database and select some field.
The use the SQL button to view the generated SQL statement. You will see that
MSQuery use a full pathname to access the database.

You can use the same syntax in your INSERT statement, but you will lose some
portability ODBC provides.

If protability is a matter for you, you should use SQLGetInfo() to query the
ODBC driver about syntax of separators, qualifier, etc ... then construct your
INSERT statement programatically.

HTH

Vincent Mascart
100425.1337@compuserve.com

-----From: santoshu@riskinc.com






Santosh Ulkande
01/27/97 10:08 AM

Try using the SQLSetConnectOption function with foption parameter =
SQL_CURRENT_QUALIFIER.
You can specify a different directory for your default source.

Santosh Ulkande





                   Environment: MSVC 1.52, Windows 95

Hi,

I have written the following as a part of a message handler responsible
for serialzing data into a database file.

  retcode = SQLAllocStmt(hdbc, &hstmt);
  if (retcode == SQL_SUCCESS)
   {
     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS);
     if (retcode == SQL_SUCCESS)
      {
       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL);
       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL);
       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL);
       ...
       ...
       ...
       retcode = SQLExecute(hstmt);
       if(retcode == SQL_ERROR)
        {
    AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
 }
       else
 {
         ...
         ...
        }
       }
     SQLFreeStmt(hstmt, SQL_DROP
   }
  ...
  ...

My problem:
When I use SQLPrepare() to preapre the "INSER INTO..." statement followed
by a couple of SQLSetParam()s followed by SQLExecute(), I always have to
have my database table in the default directory which has been set while
configuring the ODBC data source in question.

Is there a way to dynamically resolve/alter the default directory in which
SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
attempts to serialize data ??

Any help appreciated.

Mihir.
(Univeristy Researcher)






tcatchick@aesprodata.com.au
Wednesday, January 29, 1997


     I had a similar problem. Some ODBC purist may object to this method 
     but it worked for me.
     
     What I did is, once the application initialised itself I invoked a 
     dialog asking the user to select the database path. I then overrided 
     the default path name in the OBDC.INI file with the new default path. 
     Once all of the above was successfully done, then I manually opened 
     the database using this path, and used the returned handle to perform 
     my table manipulation.
     
     Regards Theron. C.


______________________________ Reply Separator _________________________________
Subject: Serializing Databases with ODBC....
Author:  mfc-l@netcom.com at INTERNET
Date:    27/1/97 12:22


                   Environment: MSVC 1.52, Windows 95
     
Hi,
     
I have written the following as a part of a message handler responsible 
for serialzing data into a database file. 
     
  retcode = SQLAllocStmt(hdbc, &hstmt); 
  if (retcode == SQL_SUCCESS) 
   {
     retcode = SQLPrepare(hstmt,"INSER INTO......",SQL_NTS); 
     if (retcode == SQL_SUCCESS) 
      {
       SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer1, NULL); 
       SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer2, NULL); 
       SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_CHAR,10, 0, Buffer3, NULL); 
       ...
       ...
       ...
       retcode = SQLExecute(hstmt);        
       if(retcode == SQL_ERROR)
        {
    AfxMessageBox("FATAL ERROR, Unable to write to database !!",MB_OK);
 } 
       else
 { 
         ...
         ...
        } 
       } 
     SQLFreeStmt(hstmt, SQL_DROP
   } 
  ...
  ...
     
My problem:
When I use SQLPrepare() to preapre the "INSER INTO..." statement followed 
by a couple of SQLSetParam()s followed by SQLExecute(), I always have to 
have my database table in the default directory which has been set while 
configuring the ODBC data source in question. 
     
Is there a way to dynamically resolve/alter the default directory in which 
SQLPrepare(hstmt,"INSERT INTO [TABLE] ......",SQL_NTS);
attempts to serialize data ??
     
Any help appreciated.
     
Mihir. 
(Univeristy Researcher)




| Вернуться в корень Архива |