aam / oracledart

Let Dart talk to Oracle
BSD 2-Clause "Simplified" License
11 stars 2 forks source link

oracledart: stmt.setInt() and stmt.setString() #18

Closed hasan3ysf closed 9 years ago

hasan3ysf commented 9 years ago

Hi Alex, Can you help in this pls,

I need to insert the below values in oracle table; [{"OrderNumber":83,"LineNumber":"1","Item":"1","Qty":"1","price":"3.2"}]

the table scheme is: ORDERS_ORDERLINES ( OrderID NUMBER, LineID NUMBER, LineNumber NUMBER, ItemID NUMBER, Qty NUMBER, Price NUMBER, DeliveryTermID NUMBER, DeliveryModeID NUMBER, Notes VARCHAR(255), lRDD DATE, deliveredQty NUMBER)

I used this SQL statement:

                       OracleStatement stmt = oracleConnection.createStatement("""
                                  INSERT INTO ORDERS_ORDERLINES
                                   (OrderID, LineNumber, ItemID, Qty,Price) 
                                  VALUES (:1,:2,:3,:4,:5)
                              """);
                         stmt.setInt(1, int.parse(oLines[i]['OrderNumber']));
                         stmt.setInt(2, int.parse(oLines[i]['LineNumber']));
                         stmt.setInt(3, int.parse(oLines[i]['Item'])); 
                         stmt.setInt(4, int.parse(oLines[i]['Qty']));
                         stmt.setInt(5, int.parse(oLines[i]['price']));
                         OracleResultset resultset = stmt.executeQuery();

but git this error:

Unhandled exception: Uncaught Error: type 'String' is not a subtype of type 'int' of 'index'. Stack Trace:

0 _StringBase.

1 savePO... (file:///G:/apps/fonix/server/bin/posthandlers/save_po.dart:37:64)

2 _RootZone.runUnary (dart:async/zone.dart:1082)

3 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)

4 _Future._propagateToListeners (dart:async/future_impl.dart:571)

5 _Future._completeWithValue (dart:async/future_impl.dart:331)

6 _Future._asyncComplete. (dart:async/future_impl.dart:393)

7 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)

8 _asyncRunCallback (dart:async/schedule_microtask.dart:48)

9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)

0 _rootHandleUncaughtError. (dart:async/zone.dart:820)

1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)

2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)

3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)

thanks

aam commented 9 years ago

I'm not sure how oLines is defined, but it seems that the problem is with second array selection in this expression: oLines[i]['OrderNumber']. Can you just print out those oLines[i]['OrderNumber']? Will that give same error?


From: Hasan Yousef notifications@github.com Sent: Thursday, October 16, 2014 4:24 AM To: aam/oracledart Subject: [oracledart] oracledart: stmt.setInt() and stmt.setString() (#18)

Hi Alex, Can you help in this pls,

I need to insert the below values in oracle table; [{"OrderNumber":83,"LineNumber":"1","Item":"1","Qty":"1","price":"3.2"}]

the table scheme is: ORDERS_ORDERLINES ( OrderID NUMBER, LineID NUMBER, LineNumber NUMBER, ItemID NUMBER, Qty NUMBER, Price NUMBER, DeliveryTermID NUMBER, DeliveryModeID NUMBER, Notes VARCHAR(255), lRDD DATE, deliveredQty NUMBER)

I used this SQL statement:

                   OracleStatement stmt = oracleConnection.createStatement("""
                              INSERT INTO ORDERS_ORDERLINES
                               (OrderID, LineNumber, ItemID, Qty,Price)
                              VALUES (:1,:2,:3,:4,:5)
                          """);
                     stmt.setInt(1, int.parse(oLines[i]['OrderNumber']));
                     stmt.setInt(2, int.parse(oLines[i]['LineNumber']));
                     stmt.setInt(3, int.parse(oLines[i]['Item']));
                     stmt.setInt(4, int.parse(oLines[i]['Qty']));
                     stmt.setInt(5, int.parse(oLines[i]['price']));
                     OracleResultset resultset = stmt.executeQuery();

but git this error:

Unhandled exception: Uncaught Error: type 'String' is not a subtype of type 'int' of 'index'. Stack Trace:

0 _StringBase.

1https://github.com/aam/oracledart/issues/1 savePO... (file:///G:/apps/fonix/server/bin/posthandlers/save_po.dart:37:64)

2https://github.com/aam/oracledart/issues/2 _RootZone.runUnary (dart:async/zone.dart:1082)

3https://github.com/aam/oracledart/issues/3 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)

4https://github.com/aam/oracledart/issues/4 _Future._propagateToListeners (dart:async/future_impl.dart:571)

5https://github.com/aam/oracledart/issues/5 _Future._completeWithValue (dart:async/future_impl.dart:331)

6https://github.com/aam/oracledart/issues/6 _Future._asyncComplete. (dart:async/future_impl.dart:393)

7https://github.com/aam/oracledart/issues/7 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)

8https://github.com/aam/oracledart/issues/8 _asyncRunCallback (dart:async/schedule_microtask.dart:48)

9https://github.com/aam/oracledart/issues/9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)

0 _rootHandleUncaughtError. (dart:async/zone.dart:820)

1https://github.com/aam/oracledart/issues/1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)

2https://github.com/aam/oracledart/issues/2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)

3https://github.com/aam/oracledart/issues/3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)

thanks

Reply to this email directly or view it on GitHubhttps://github.com/aam/oracledart/issues/18.

hasan3ysf commented 9 years ago

Sorry Alex it is my mistake, the oLines are not read correctly, I was missing json.decode to read them properly.