This Question is Answered

15 "helpful" answers available (3 pts)
1 2 Previous Next
Click to view mgordon's profile Curl mgordon 48 posts since
Oct 17, 2007
15. Re: Need help for database BasicConnection Jul 2, 2008 12:52 PM
in response to: hokada
If you are using Oracle as your database there are some quirks that you have to work around. Here is what I discovered. I will post some sample files when I get time.

1. As mentioned earlier, use serialize? = true when you create your connection.

      let nc:BasicConnection = 
          {BasicConnection {url server}, serialize? = true}


2. cdbc-server.xml (in tomcat/conf/Catalina/localhost)

The following ResourceLink was left out of the example given in the documentation. Without it, the "cdbc/database" item defined in server.xml will not be found, and then the "cdbc-mysql" resource will be used instead of "cdbc-oracle".

      <ResourceLink name="cdbc/database"
          global="cdbc/database"
          type="java.lang.String" />


The default-schema resource links in the sample cdbc-server.xml were incorrect. Use one like this (leaving off the trailing /ja or /en).
      <ResourceLink name="cdbc/default-schema/oracle"
            global="cdbc/default-schema/oracle"
            type="java.lang.String" />


3. Setting up the JDBC driver (in tomcat/conf/server.xml)

Every JDBC driver has different requiremnts for configuration. The XML syntax for the Oracle JDBC driver looks like this. Note that you'll need to change the username, password, and possibly localhost to some other host name or IP address.

    <Resource name="cdbc-oracle" 
      auth="Container" type="javax.sql.DataSource"
      username="CDBC_USER"
      password="your-secret-password"
      driverClassName="oracle.jdbc.driver.OracleDriver"
      url="jdbc:oracle:thin:@localhost:1521:XE"
      connectionProperties="SetBigStringTryClob=true"
    />


(I'm actually not sure about the connectionProperties value but this worked for me.)

4. Other changes to server.xml

You must use jdbc transaction control, or none. The example uses "mysql" but then the server will attempt execute nonstandard SQL statements START TRANSACTION and COMMIT. If you specify "jdbc", the server will use the JDBC connnection.commit() call to commit each update.

    <Environment name="cdbc/transaction-control"
        type="java.lang.String"
        value="jdbc"
    />

Here is the "default-schema" that I used.

    <Environment name="cdbc/default-schema/oracle"
        type="java.lang.String"
        value="CDBC_USER"
    />


5. Use upper case table names

It seems that if a table name is not all uppercase then it must be quoted in the SQL statements. The current version of the BasicConnection does not use quotes around table names, so your table names must be all upper case if you are using Oracle.
Click to view Harry's profile Level 1 Harry 20 posts since
Jun 19, 2008
16. Re: Need help for database BasicConnection Jul 3, 2008 4:46 AM
in response to: mgordon
Thanks to all,

my small Curl Oracle-Test-Applet is running and works.

Interesting detail:
this Action DOESN'T commit changes in the remote Oracle database.
1.
{CommandButton
label = "change",
style = "standard",
{on Action at btn:CommandButton do
{conn.execute "SCOTT","update emp set ename = 'NewName',hiredate='03.07.2008' where empno=1"}
{conn.execute "SCOTT","commit"} }}

2.
but this commits changes!
{CommandButton
label = "change",
style = "standard",
{on Action at btn:CommandButton do
{conn.execute "SCOTT","update emp set ename = 'NewName',hiredate='03.07.2008' where empno=1;commit"}}}

?????

It's possible to call Oracle stored-procedures/functions (parameters/return-value) ?
Any support for Ref Cursors?

?????

To Curl, remote SQL and Oracle please read this:
http://developers.curl.com/blogs/community_blog/2008/07/01/curl-customer-presents-at-catalyst-conference-san-diego-june-26-2008
RMH wrotes:

If I understand your post, you are asking if Curl has the ability to connect natively to databases across the network in order to execute SQL queries directly.
If that is the question than the answer is no.

My test showed that the above update (see No 2.) works with use of CDBC/JDBC.
For sure, that's not a native Oracle SQL*Net connection but a JDBC connection.

Some misunderstandings here?

With PHP you could already use OCI8:
This extension allows you to access Oracle databases using the Oracle Call Interface (OCI8) and Oracle's standard cross-version connectivity.
Support binding of PHP variables to Oracle placeholders, have full LOB, FILE and ROWID support, and allow you to use
user-supplied define variables.
"http://pecl.php.net/package/oci8"

Our environment:

A. Local Desktop
Windows XP, Tomcat 6.0.14 (problems with native libaries in 6.0.16),
Curl 7.0.1000 beta , Oracle jdbc driver "ojdbc4.jar"
B. Remote Database Server
HP-UX B.11.23 Itanium 64-bit
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit

Click to view Harry's profile Level 1 Harry 20 posts since
Jun 19, 2008
17. Re: Need help for database BasicConnection Jul 4, 2008 9:23 AM
in response to: Harry
Call Oracle packages from Curl?

Implementing getter-setter functions/methods in CURL by use of Oracle database packages.

Advantages:


  • hides tablenames, columns and other details in Curl application.
  • no DML or DLL calls in Curl program -> conn.execute("select ...")
  • all SQL (i.e. ref cursor, bulk select/insert/update/delete/commit/rollback, ...) in the backend database:-)
  • no restriction of SQL-complexity (joins, hierarchical queries: connect by/start with, ...).
  • use of remote database DDL functionality (alter, create, ...)
  • use of Oracle DBMS packages, Job control.
  • use of native/compilable Oracle PL/SQL language in the remote database.

Only first thoughts with tables scott.EMP and DEPT, very uncomplete:


1. {conn.callStoredProcedure("SCOTT","MyPackage.getDataEmpDept (dataArray[])
using bind_variable1, bind_variable2, readonly_var /* i.e. empno, deptno, ... */
return status, count, ...")}

2. {conn.callStoredProcedure("SCOTT","MyPackage.setDataEmpDept (dataArray[])
return status, count, ...")}

3. {conn.callStoredProcedure("SCOTT","MyPackage.commit (MyPackage.rollback, MyPackage.set_transaction)
return status ...")}
4. ...

In C notation (i can't do it yet in Curl)

int status; /* ORA-NNNN (DBMS return code, success, no success, ...) */
int count; /* number of rows: selected, inserted, updated, deleted */
int readonly_var; /* readonly or lock records (select ... {for update of}) */

Array for get/set data (one of many).
Mabye a second array only for setting.

struct dataArray_
{
int empno,
char ename 10,
int deptno,
char dname 14,
...
int siud, /* 0=from DB selected, 1=from user input, 3=updated, 4=deleted */
} dataArray MAX_ROWS;


or dynamic dataArray[] like malloc() in C (don't know for Curl)

Curl for presentation and user interaction.

Flow:
A. Call 1 could load parts of DataGrids, TreeViews, Forms or internal Curl variables, or ...
B. user interaction (events)
C. Call 2 would insert, updated and delete data in the database.

Please Curl experts.


Any comments?

Click to view mgordon's profile Curl mgordon 48 posts since
Oct 17, 2007
18. Re: Need help for database BasicConnection Jul 10, 2008 10:54 AM
in response to: Harry
I'm not sure about some your questions. Here's a little information about what our servlet is doing, which should help you figure out the answer, or what experiments to try.

When you call conn.execute, the stmts parameter you pass in is a String, and it can be any number of sql statements. On the server side, we break this up into individual statements and execute them one by one. At the end, we call the jdbcConn.commit (and we set autocommit off before executing the first statement). So each call to conn.execute is a single transaction consisting of all of the statements you provided. Any statement your JDBC driver allows will be allowed by CDBC. It is simply passing them along to the JDBC driver. I'm not sure if that gives you access to stored procedures. Let us know what you find.

You can also study the example code I posted for exploring databases and tables. That might answer some of your other questions. In this example, you can navigate to a table and it is displayed in a RecordGrid. You can click on a field in the grid and edit the value. You can click the Save button to commit the changes back to the database. If you look at the code, you won't see any SQL at all. It's all handled by the ConnectedRecordSet and the BasicConnection.

As far as accessing data in your Curl code goes, its all done with RecordSet, which is a collection of Records. If you have a Record r, you can write r"empno" to get the empno field, and set r"empno" = 234 to change it.
Click to view hokada's profile Level 1 hokada 12 posts since
Jun 29, 2008
19. Re: Need help for database BasicConnection Jul 10, 2008 6:49 PM
in response to: mgordon
Harry,

If you want to execute the stored procedure, you will be able to use the BasicConnection.execute method. I tried following steps, and then it does work.

1. create the table and the stored procedure.

CREATE TABLE cdbc_test (
COL1 NUMBER(10),
COL2 VARCHAR2(10),
COL3 DATE
);

CREATE OR REPLACE PROCEDURE cdbc_proc (col1 IN VARCHAR2, col2 IN NUMBER)
AS
BEGIN
INSERT INTO cdbc_test VALUES (col1, col2, sysdate);
COMMIT;
END;
/


2. run the following applet.

{curl 6.0 applet}

{import * from CURL.DATA-ACCESS.BASE}
{import * from CURL.DATA-ACCESS.CONNECTED}

{value
def conn =
{BasicConnection
{url "http://localhost:8080/cdbc-server/CdbcServlet"},
serialize? = true
}

{conn.execute"your schema name","CALL cdbc_proc('Foo', 1);"}

def rs =
{conn.create-record-set"your schema name","select * from CDBC_TEST",
request-modifiable? = true
}

{RecordGrid record-source = rs}
}


Click to view Harry's profile Level 1 Harry 20 posts since
Jun 19, 2008
20. Re: Need help for database BasicConnection Jul 11, 2008 2:25 AM
in response to: mgordon

Many Thanks,

tried exploring databases and tables sample with remote database Oracle 10g R2 on Hp-UX 64bit.

1. selected all records from table "scott.emp"

2. Button "Save" throws error:

An applet is about to throw the unexpected exception described below. Press "Continue" to allow that exception to be thrown (and possibly ignored), or "Quit Applet" to cause the applet to quit.

ConnectedDataException: No keys found for query 'UPDATE EMP SET EMPNO=2, ENAME='TEST3', JOB='TEST', MGR=4711, HIREDATE='2008-06-30', SAL=0, COMM=0, DEPTNO=0, NUMBER22=0'.

What means "No keys found " ? There is a primary key constraint:

ALTER TABLE SCOTT.EMP ADD (CONSTRAINT EMP_PK PRIMARY KEY (EMPNO) ...

3. Why "UPDATE EMP SET EMPNO=2,..." ?

- Better: "update emp set ename='TEST3' where emp=2".

- And why update columns (AND primrary key!) where no changes were made?

4. Button "Delete" throws error (clicked on a line and pressed the button)

- ConnectedDataException: No keys found for query 'DELETE FROM EMP'.

- Without a where-clause this would delete ALL records :-(

- How to delete (save changed ) only "marked" records.

Click to view Harry's profile Level 1 Harry 20 posts since
Jun 19, 2008
21. Re: Need help for database BasicConnection Jul 11, 2008 5:06 AM
in response to: hokada
Great, after changing into

CREATE OR REPLACE PROCEDURE cdbc_proc (col1 IN NUMBER, col2 IN VARCHAR2)
AS
BEGIN
INSERT INTO cdbc_test VALUES (col1, col2, sysdate);
COMMIT;
END;

{conn.execute"SCOTT","CALL cdbc_proc(1,'Foo');"}

IT WORKS !

Another small but very good example what curl has to offer http://developers.curl.com/images/emoticons/happy.gif

How to give back values (also arrays - type Record/Table in Oracle) from the stored procedure?

PROCEDURE cdbc_proc (col1 IN NUMBER, col2 IN VARCHAR2, col3 OUT varchar2)

1 2 Previous Next