Problem
We would like to validate that an Oracle SQL statement is syntactically correct, only references known tables, views, columns, etc.
OCI for Oracle 12c – possible to parse only
Using OCI (Oracle Call Interface) for Oracle 12c it is possible to first create a statement using OCIStmtPrepare() and then call OCIStmtExecute() using the special mode OCI_PARSE_ONLY. This will cause Oracle to parse the statement without actually executing it.
OCCI for Oracle 12 – impossible?
Now, we are using OCCI (Oracle C++ Call Interface) for Oracle 12c. It seems there is no way to force Oracle to parse the statement without also executing it. When calling the Connection::createStatement() method and then calling Statement::status() on the returned statement, Oracle will tell you that the statement is PREPARED but parsing the statement is deferred until the statement is actually executed calling e.g. Statement::execute() so there does not seem to be a way to parse the statement without executing.
Is anybody aware of a way to parse without executing a SQL statement using OCCI for Oracle 12c?
Related
I'm trying to change the MySQL command delimiter so I can create a procedure with multiple commands in it. However, the delimiter command does not seem to be recognised on MySQL 5.1.47. I tested it on MySQL 5.0.91, and it did work there.
DELIMITER //;
DELIMITER ;//
I'm trying to run this from phpmyadmin, in both situations. Using 5.0.91 instead isn't an option because I need to use events (CREATE EVENT).
Error message:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //' at line 1
Is there a reason it's not working, or is there an alternative to accomplish the same thing (creating a procedure with multiple queries)?
DELIMITER is not a MySQL command. It's a command that your MySQL client needs to support. I was running PHPMyAdmin 2.8.2.4, which didn't support it. When I upgraded to the newest version, which is currently 3.4.9, it worked just fine. Your MySQL version has nothing to do with DELIMITER and whether it's supported or not.
You don't need to delimit the DELIMIT statements
DELIMITER //
procedure here etc
DELIMITER ;
Exactly as per "Defining Stored Programs" in the MySQL docs.
And if you can control versions, the latest is 5.5.20. Why not use that?
Edit:
The error message indicates an error in the previous statement... if this can't be seem force it thus
; /* <- force previous statement termination */ DELIMITER //
procedure here etc
DELIMITER ;
I m doing a software in c++ that permit to access to some rdbms with qt library.
The software is only for pc.
The software need to know the name of rdbms and version beacuse the program needs to choose some sql query to execute. Is there any way to retrieve thisdata in any rdbms?
Is there any way to retrieve thisdata in any rdbms?
This is specific to each RDBMS - for example, in Oracle, you can do
select *
from v$version;
but in other RDBMS this view does not exist.
Some possible approaches:
You need to define connect parameters somewhere anyways. Even they are often RDBMS-specific, so you could simply add another parameter like SQLFlavor=Oracle or SQLFlavor=MySQL and then use the value of SQLFlavor in your code to determine which SQL statement to use
You can use some heuristics to find out the RDBMS. For example, query the v$version view - if it does not exist, you will get an error and you know that it is not Oracle and you can continue with the next try (like SELECT VERSION() to see if it is MySQL). Otherwise, you can use the result to find out the concrete Oracle version.
Is there a c++(preferably MFC) database object that can execute multiple SQL statements(as in a script) in one instruction? Like this :
DatabaseObject.RunSQL("Insert into GN_Version values (1,2,3,4); Insert into GN_Version values (5,2,3,4); Insert into GN_Version values (3,2,3,4);");
After doing some research, I found that with the SQL Server ODBC Driver, CDatabase.ExecuteSQL can execute multiple statements in one instruction.
Have worked with MFC together with SQL Server for several years. Have never encountered such a function. Usually, there is some tokenizer involved to accomplish that.
As a comparison, SQLite does support such multi-statements through its APIs.
I'm locally running an instance of Oracle 11gR2 for testing. I'm connecting to it with OLEDB using VC++. I use CCommand and I'm able to select, update, insert and delete from my tables.
What I can't do right now is execute stored procedures.
It is a simple stored procedure that inserts a row to my table. I can run it from SQL Plus without a hitch. However, when I come to execute it from my code, it doesn't work. I get a 80040e14 error.
It's pretty straightforward, but here is the line anyway.
hr = cmd.Open(session, "exec get_item_count");
Any ideas?
EXEC is SQL*Plus syntax. It is not valid outside SQL*Plus (and a variety of PL/SQL GUIs that implement many of the features SQL*Plus provides).
You probably want something like this (using ODBC syntax)
hr = cmd.Open(session, "{call get_item_count}");
or this (using Oracle syntax)
hr = cmd.Open(session, "begin get_item_count; end;");
If you use the Oracle syntax, the same syntax will work both in SQL*Plus and from your application. SQL*Plus does not understand ODBC syntax. However, other OLE DB providers will support ODBC syntax so ODBC syntax is portable across different database engines.
Additionally, if you have a PL/SQL object that retrieves an item count, that should be a stored function not a stored procedure. You say that the procedure is inserting a row into your table, which is something that a procedure should do and a function should not, but the name of the object get_item_count doesn't seem to match your description of what it is doing.
I am referring to http://www.postgresql.org/docs/8.1/static/libpq.html
I try to find an example of C/C++ to call PostgreSQL stored procedure. However, I cannot find one. Can anyone point me the right direction?
As as previously been answered, the easiest way is to use SELECT myStoredProcedure(1,2,3). You can also use the fast-path call interface to call a function directly. See http://www.postgresql.org/docs/current/static/libpq-fastpath.html for reference. But note that if you are working on modern versions of PostgreSQL, you're likely better off using the regular interface and a prepared statement.
You just need to execute a SQL statement like this one:
SELECT myStoredProcedure(1,2,3);
This can for example be done using PQexec(), just like with any other SQL statement. An example program that sends SQL statements to a database can be found in section 28.17. of the documentation