|
1 | 1 | #------------------------------------------------------------------------------ |
2 | | -# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | +# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | #------------------------------------------------------------------------------ |
4 | 4 |
|
5 | 5 | #------------------------------------------------------------------------------ |
|
16 | 16 | #------------------------------------------------------------------------------ |
17 | 17 |
|
18 | 18 | import cx_Oracle |
19 | | -import SampleEnv |
| 19 | +import sample_env |
20 | 20 |
|
21 | | -connection = cx_Oracle.connect(SampleEnv.GetMainConnectString()) |
| 21 | +connection = cx_Oracle.connect(sample_env.get_main_connect_string()) |
22 | 22 | cursor = connection.cursor() |
23 | 23 |
|
24 | 24 | # define data to insert |
25 | | -dataToInsert = [ |
| 25 | +data_to_insert = [ |
26 | 26 | (1016, 10, 'Child B of Parent 10'), |
27 | 27 | (1017, 10, 'Child C of Parent 10'), |
28 | 28 | (1018, 20, 'Child D of Parent 20'), |
|
39 | 39 | from ChildTable""") |
40 | 40 | count, = cursor.fetchone() |
41 | 41 | print("number of rows in child table:", int(count)) |
42 | | -print("number of rows to insert:", len(dataToInsert)) |
| 42 | +print("number of rows to insert:", len(data_to_insert)) |
43 | 43 |
|
44 | 44 | # old method: executemany() with data errors results in stoppage after the |
45 | 45 | # first error takes place; the row count is updated to show how many rows |
46 | 46 | # actually succeeded |
47 | 47 | try: |
48 | 48 | cursor.executemany("insert into ChildTable values (:1, :2, :3)", |
49 | | - dataToInsert) |
| 49 | + data_to_insert) |
50 | 50 | except cx_Oracle.DatabaseError as e: |
51 | 51 | error, = e.args |
52 | 52 | print("FAILED with error:", error.message) |
|
64 | 64 |
|
65 | 65 | # new method: executemany() with batch errors enabled (and array DML row counts |
66 | 66 | # also enabled) results in no immediate error being raised |
67 | | -cursor.executemany("insert into ChildTable values (:1, :2, :3)", dataToInsert, |
68 | | - batcherrors = True, arraydmlrowcounts = True) |
| 67 | +cursor.executemany("insert into ChildTable values (:1, :2, :3)", |
| 68 | + data_to_insert, batcherrors=True, arraydmlrowcounts=True) |
69 | 69 |
|
70 | 70 | # where errors have taken place, the row count is 0; otherwise it is 1 |
71 | | -rowCounts = cursor.getarraydmlrowcounts() |
72 | | -print("Array DML row counts:", rowCounts) |
| 71 | +row_counts = cursor.getarraydmlrowcounts() |
| 72 | +print("Array DML row counts:", row_counts) |
73 | 73 |
|
74 | 74 | # display the errors that have taken place |
75 | 75 | errors = cursor.getbatcherrors() |
|
0 commit comments