?
Solved

Any OCI API that can escape chars like ' in SQL...

Posted on 2004-04-13
6
Medium Priority
?
1,483 Views
Last Modified: 2012-08-14
Hi*!
     I have implemented a module to use the OCI interface for Oracle in C/C++. Sometimes my SQL statement contains chars like ' and while excecuting I get OCI errors. Now I am planning to sort this problem out. Is there any API in OCI like in prel DBI that takes the SQL string and escapes all escapeable chars. Or do i have to write a function in C/C++ my self to parse the SQL statement correctly.
Thanks in advance,
Regards,
Usman.
0
Comment
Question by:u_riaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 10812521
Normally you have to use two ' characters to represent ' in the SQL. OCI has to accept this way of passing constants.
0
 
LVL 12

Expert Comment

by:catchmeifuwant
ID: 10812706
For eg., if you want select details from DB (with quotes stored) then you need to do :

SQL> insert into emp(empno,ename)
  2  values(999,'Riaz''s');

1 row created.

SQL> commit;

Commit complete.

SQL> select empno,ename from emp
  2  where ename = 'Riaz''s';

     EMPNO ENAME
---------- ----------
       999 Riaz's

SQL>

------------

or use bind variables to handle the data
0
 

Author Comment

by:u_riaz
ID: 10812983
Thanks for the reply. I know how to escape those characters. What i wanted to know is the API or Function in OCI that I can Call something like

char szSQLStmt[256] = "select something from something where something = 'usman's name';"
And i can call some function to escape it e.g.

SomeOCIFunctionIamLookingFor(szSQLStmt);

Now this function does the magic and escapes the SQL String.

Thanks,
Usman.
0
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 1000 total points
ID: 10813098
why don't you use bind variables?

char name_buf[100];

select something from something
where something = :name_buf;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question