?
Solved

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

Posted on 2004-04-13
6
Medium Priority
?
1,469 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

777 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