|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <jni.h> |
|
17 #include "DbmsStatement.h" |
|
18 #include "DbmsConnection.h" |
|
19 #include "DbmsResultSet.h" |
|
20 #include "Utils.h" |
|
21 #include "dbmsjni/com_symbian_dbms_jdbc_DbmsStatement.h" |
|
22 #include <stdlib.h> |
|
23 |
|
24 // // |
|
25 // DbmsStatement peer |
|
26 // // |
|
27 |
|
28 DbmsStatement::DbmsStatement(DbmsConnection* aConnection){ |
|
29 iConnection = aConnection; |
|
30 } |
|
31 |
|
32 DbmsStatement::~DbmsStatement(){ |
|
33 } |
|
34 |
|
35 void DbmsStatement::Close(){ |
|
36 iView.Close(); |
|
37 } |
|
38 |
|
39 // // |
|
40 // JNI |
|
41 // // |
|
42 |
|
43 /* |
|
44 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
45 * Method: _create |
|
46 * Signature: (I)I |
|
47 */ |
|
48 JNIEXPORT jint JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1create |
|
49 (JNIEnv *, jobject, jint aPeer){ |
|
50 DbmsConnection* connection = (DbmsConnection*) aPeer; |
|
51 DbmsStatement* statement = new DbmsStatement(connection); |
|
52 return (jint) statement; |
|
53 } |
|
54 |
|
55 /* |
|
56 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
57 * Method: _executeUpdate |
|
58 * Signature: (ILjava/lang/String;)I |
|
59 */ |
|
60 JNIEXPORT jint JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1executeUpdate |
|
61 (JNIEnv *aEnv, jobject, jint aPeer, jstring aString){ |
|
62 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
63 RJString sql(*aEnv, aString); |
|
64 RDbNamedDatabase& db = statement->iConnection->iDatabase; |
|
65 TInt res = db.Execute(sql); |
|
66 return res; |
|
67 } |
|
68 |
|
69 /* |
|
70 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
71 * Method: _executeQuery |
|
72 * Signature: (ILjava/lang/String;)I |
|
73 */ |
|
74 JNIEXPORT jint JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1executeQuery |
|
75 (JNIEnv *aEnv, jobject, jint aPeer, jstring aString){ |
|
76 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
77 RJString sql(*aEnv, aString); |
|
78 TDbQuery query (sql); |
|
79 TInt res = statement->iView.Prepare(statement->iConnection->iDatabase, query, RDbRowSet::EReadOnly); |
|
80 if ( res < 0 ) { |
|
81 return (jint) res; |
|
82 } else { |
|
83 res = statement->iView.EvaluateAll(); |
|
84 if ( res < 0 ) { |
|
85 return (jint) res; |
|
86 } else { |
|
87 DbmsResultSet* resultSet = new DbmsResultSet(statement); |
|
88 return (jint) resultSet; |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 /* |
|
94 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
95 * Method: _close |
|
96 * Signature: (I)V |
|
97 */ |
|
98 JNIEXPORT void JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1close |
|
99 (JNIEnv *, jobject, jint aPeer){ |
|
100 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
101 statement->Close(); |
|
102 delete statement; |
|
103 } |
|
104 |
|
105 /* |
|
106 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
107 * Method: _begin |
|
108 * Signature: (I)V |
|
109 */ |
|
110 JNIEXPORT jint JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1begin |
|
111 (JNIEnv *, jobject, jint aPeer) { |
|
112 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
113 return statement->iConnection->iDatabase.Begin(); |
|
114 } |
|
115 |
|
116 /* |
|
117 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
118 * Method: _commit |
|
119 * Signature: (I)V |
|
120 */ |
|
121 JNIEXPORT jint JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1commit |
|
122 (JNIEnv *, jobject, jint aPeer) { |
|
123 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
124 return statement->iConnection->iDatabase.Commit(); |
|
125 } |
|
126 |
|
127 /* |
|
128 * Class: com_symbian_dbms_jdbc_DbmsStatement |
|
129 * Method: _rollback |
|
130 * Signature: (I)V |
|
131 */ |
|
132 JNIEXPORT void JNICALL Java_com_symbian_dbms_jdbc_DbmsStatement__1rollback |
|
133 (JNIEnv *, jobject, jint aPeer) { |
|
134 DbmsStatement* statement = (DbmsStatement*) aPeer; |
|
135 statement->iConnection->iDatabase.Rollback(); |
|
136 } |
|
137 |
|
138 |