ODBC Stored Procedure and varchar argument 
Author Message
 ODBC Stored Procedure and varchar argument

Hi,

I am using MFC and trying to call a stored procedure using the
CDatabase::Execute() command.

It has been working great until we came upon an argument that uses a varchar
(say a string).

The problem is when the data for the argument has a single quote (') because
the ODBC driver cannot properly parse out this and the remaining arguments.

I may have to use a CRecordset and bind some parameters and call a stored
procedure... any good links to articles on how to do this properly. I do not
have much time to get this solution finished (a day or two max).

Thanks.
-Chris

----------------------------
 if(!m_database.IsOpen())
 {
  TRACE("The database is not open\n");
  return;
 }

 try
 {
  m_database.ExecuteSQL(m_strSQL);
 }
 catch(CDBException * e)
 {
       TRACE(e->m_strError);
        e->Delete();
 }



Sat, 20 Sep 2003 04:06:39 GMT  
 ODBC Stored Procedure and varchar argument
I found this one:
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_r...
t.3a_.declaring_a_class_for_a_predefined_query_.28.odbc.29.htm


Quote:
> Hi,

> I am using MFC and trying to call a stored procedure using the
> CDatabase::Execute() command.

> It has been working great until we came upon an argument that uses a
varchar
> (say a string).

> The problem is when the data for the argument has a single quote (')
because
> the ODBC driver cannot properly parse out this and the remaining
arguments.

> I may have to use a CRecordset and bind some parameters and call a stored
> procedure... any good links to articles on how to do this properly. I do
not
> have much time to get this solution finished (a day or two max).

> Thanks.
> -Chris

> ----------------------------
>  if(!m_database.IsOpen())
>  {
>   TRACE("The database is not open\n");
>   return;
>  }

>  try
>  {
>   m_database.ExecuteSQL(m_strSQL);
>  }
>  catch(CDBException * e)
>  {
>        TRACE(e->m_strError);
>         e->Delete();
>  }



Sat, 20 Sep 2003 04:33:05 GMT  
 ODBC Stored Procedure and varchar argument
You can use a mix double quote and single quote

On Mon, 2 Apr 2001 13:33:05 -0700, "newsgroup poster"

Quote:

>I found this one:
>http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_r...
>t.3a_.declaring_a_class_for_a_predefined_query_.28.odbc.29.htm



>> Hi,

>> I am using MFC and trying to call a stored procedure using the
>> CDatabase::Execute() command.

>> It has been working great until we came upon an argument that uses a
>varchar
>> (say a string).

>> The problem is when the data for the argument has a single quote (')
>because
>> the ODBC driver cannot properly parse out this and the remaining
>arguments.

>> I may have to use a CRecordset and bind some parameters and call a stored
>> procedure... any good links to articles on how to do this properly. I do
>not
>> have much time to get this solution finished (a day or two max).

>> Thanks.
>> -Chris

>> ----------------------------
>>  if(!m_database.IsOpen())
>>  {
>>   TRACE("The database is not open\n");
>>   return;
>>  }

>>  try
>>  {
>>   m_database.ExecuteSQL(m_strSQL);
>>  }
>>  catch(CDBException * e)
>>  {
>>        TRACE(e->m_strError);
>>         e->Delete();
>>  }



Sat, 20 Sep 2003 05:02:35 GMT  
 ODBC Stored Procedure and varchar argument
So what happens when my data has a double quote in it?

This doesn't really solve the problem.

-Chris


Quote:
> You can use a mix double quote and single quote

> On Mon, 2 Apr 2001 13:33:05 -0700, "newsgroup poster"

> >I found this one:

>http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_r...
e
> >t.3a_.declaring_a_class_for_a_predefined_query_.28.odbc.29.htm



> >> Hi,

> >> I am using MFC and trying to call a stored procedure using the
> >> CDatabase::Execute() command.

> >> It has been working great until we came upon an argument that uses a
> >varchar
> >> (say a string).

> >> The problem is when the data for the argument has a single quote (')
> >because
> >> the ODBC driver cannot properly parse out this and the remaining
> >arguments.

> >> I may have to use a CRecordset and bind some parameters and call a
stored
> >> procedure... any good links to articles on how to do this properly. I
do
> >not
> >> have much time to get this solution finished (a day or two max).

> >> Thanks.
> >> -Chris

> >> ----------------------------
> >>  if(!m_database.IsOpen())
> >>  {
> >>   TRACE("The database is not open\n");
> >>   return;
> >>  }

> >>  try
> >>  {
> >>   m_database.ExecuteSQL(m_strSQL);
> >>  }
> >>  catch(CDBException * e)
> >>  {
> >>        TRACE(e->m_strError);
> >>         e->Delete();
> >>  }



Sat, 20 Sep 2003 05:06:41 GMT  
 ODBC Stored Procedure and varchar argument
2 options

CString szsql = _T("Select all from table where name = 'bob'");  works

you can also use \" to embed

On Mon, 2 Apr 2001 14:06:41 -0700, "Chris Adamson"

Quote:

>So what happens when my data has a double quote in it?

>This doesn't really solve the problem.

>-Chris



>> You can use a mix double quote and single quote

>> On Mon, 2 Apr 2001 13:33:05 -0700, "newsgroup poster"

>> >I found this one:

>>http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_r...
>e
>> >t.3a_.declaring_a_class_for_a_predefined_query_.28.odbc.29.htm



>> >> Hi,

>> >> I am using MFC and trying to call a stored procedure using the
>> >> CDatabase::Execute() command.

>> >> It has been working great until we came upon an argument that uses a
>> >varchar
>> >> (say a string).

>> >> The problem is when the data for the argument has a single quote (')
>> >because
>> >> the ODBC driver cannot properly parse out this and the remaining
>> >arguments.

>> >> I may have to use a CRecordset and bind some parameters and call a
>stored
>> >> procedure... any good links to articles on how to do this properly. I
>do
>> >not
>> >> have much time to get this solution finished (a day or two max).

>> >> Thanks.
>> >> -Chris

>> >> ----------------------------
>> >>  if(!m_database.IsOpen())
>> >>  {
>> >>   TRACE("The database is not open\n");
>> >>   return;
>> >>  }

>> >>  try
>> >>  {
>> >>   m_database.ExecuteSQL(m_strSQL);
>> >>  }
>> >>  catch(CDBException * e)
>> >>  {
>> >>        TRACE(e->m_strError);
>> >>         e->Delete();
>> >>  }



Sat, 20 Sep 2003 23:08:44 GMT  
 ODBC Stored Procedure and varchar argument
Thanks Dave,

I was thinking that delimiters would work but never got around to trying it
(yet). Been busy with another part of the project.

-Chris


Quote:
> 2 options

> CString szsql = _T("Select all from table where name = 'bob'");  works

> you can also use \" to embed

> On Mon, 2 Apr 2001 14:06:41 -0700, "Chris Adamson"

> >So what happens when my data has a double quote in it?

> >This doesn't really solve the problem.

> >-Chris



> >> You can use a mix double quote and single quote

> >> On Mon, 2 Apr 2001 13:33:05 -0700, "newsgroup poster"

> >> >I found this one:

>>http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_r...
s
> >e
> >> >t.3a_.declaring_a_class_for_a_predefined_query_.28.odbc.29.htm



> >> >> Hi,

> >> >> I am using MFC and trying to call a stored procedure using the
> >> >> CDatabase::Execute() command.

> >> >> It has been working great until we came upon an argument that uses a
> >> >varchar
> >> >> (say a string).

> >> >> The problem is when the data for the argument has a single quote (')
> >> >because
> >> >> the ODBC driver cannot properly parse out this and the remaining
> >> >arguments.

> >> >> I may have to use a CRecordset and bind some parameters and call a
> >stored
> >> >> procedure... any good links to articles on how to do this properly.
I
> >do
> >> >not
> >> >> have much time to get this solution finished (a day or two max).

> >> >> Thanks.
> >> >> -Chris

> >> >> ----------------------------
> >> >>  if(!m_database.IsOpen())
> >> >>  {
> >> >>   TRACE("The database is not open\n");
> >> >>   return;
> >> >>  }

> >> >>  try
> >> >>  {
> >> >>   m_database.ExecuteSQL(m_strSQL);
> >> >>  }
> >> >>  catch(CDBException * e)
> >> >>  {
> >> >>        TRACE(e->m_strError);
> >> >>         e->Delete();
> >> >>  }



Sun, 21 Sep 2003 08:21:36 GMT  
 ODBC Stored Procedure and varchar argument
I believe Dave has pointed to the right way.


Sun, 21 Sep 2003 16:33:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. odbc and stored procedures

2. Stored Procedure's Fetch Fails Via ODBC

3. Calling a store procedure with ODBC

4. ODBC: Passing embedded quotes to stored procedures

5. ODBC + Oracle + MFC + Stored Procedure

6. MFC ODBC classes and Stored Procedures

7. HowTo: ODBC and Stored Procedures

8. Empty output parameters when executing stored procedure through ODBC

9. ODBC & Stored Procedures

10. store procedure (ODBC)

11. Stored Procedure's Fetch Fails Via ODBC

12. ODBC and stored procedures

 

 
Powered by phpBB® Forum Software