mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-12 18:06:16 +00:00
updated oracleai_demo.ipynb (#22635)
The outer try/except block handles connection errors, and the inner try/except block handles SQL execution errors, providing detailed error messages for both. try: conn = oracledb.connect(user=username, password=password, dsn=dsn) print("Connection successful!") cursor = conn.cursor() try: cursor.execute( """ begin -- Drop user begin execute immediate 'drop user testuser cascade'; exception when others then dbms_output.put_line('Error dropping user: ' || SQLERRM); end; --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
035a9c9609
commit
835926153b
@ -86,8 +86,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"import oracledb\n",
|
"import oracledb\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# please update with your username, password, hostname and service_name\n",
|
"# Update with your username, password, hostname, and service_name\n",
|
||||||
"# please make sure this user has sufficient privileges to perform all below\n",
|
|
||||||
"username = \"\"\n",
|
"username = \"\"\n",
|
||||||
"password = \"\"\n",
|
"password = \"\"\n",
|
||||||
"dsn = \"\"\n",
|
"dsn = \"\"\n",
|
||||||
@ -97,40 +96,45 @@
|
|||||||
" print(\"Connection successful!\")\n",
|
" print(\"Connection successful!\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
" cursor = conn.cursor()\n",
|
" cursor = conn.cursor()\n",
|
||||||
|
" try:\n",
|
||||||
" cursor.execute(\n",
|
" cursor.execute(\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" begin\n",
|
" begin\n",
|
||||||
" -- drop user\n",
|
" -- Drop user\n",
|
||||||
" begin\n",
|
" begin\n",
|
||||||
" execute immediate 'drop user testuser cascade';\n",
|
" execute immediate 'drop user testuser cascade';\n",
|
||||||
" exception\n",
|
" exception\n",
|
||||||
" when others then\n",
|
" when others then\n",
|
||||||
" dbms_output.put_line('Error setting up user.');\n",
|
" dbms_output.put_line('Error dropping user: ' || SQLERRM);\n",
|
||||||
" end;\n",
|
" end;\n",
|
||||||
|
" \n",
|
||||||
|
" -- Create user and grant privileges\n",
|
||||||
" execute immediate 'create user testuser identified by testuser';\n",
|
" execute immediate 'create user testuser identified by testuser';\n",
|
||||||
" execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n",
|
" execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n",
|
||||||
" execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n",
|
" execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n",
|
||||||
" execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n",
|
" execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n",
|
||||||
" execute immediate 'grant create mining model to testuser';\n",
|
" execute immediate 'grant create mining model to testuser';\n",
|
||||||
"\n",
|
" \n",
|
||||||
" -- network access\n",
|
" -- Network access\n",
|
||||||
" begin\n",
|
" begin\n",
|
||||||
" DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n",
|
" DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n",
|
||||||
" host => '*',\n",
|
" host => '*',\n",
|
||||||
" ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n",
|
" ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n",
|
||||||
" principal_name => 'testuser',\n",
|
" principal_name => 'testuser',\n",
|
||||||
" principal_type => xs_acl.ptype_db));\n",
|
" principal_type => xs_acl.ptype_db)\n",
|
||||||
|
" );\n",
|
||||||
" end;\n",
|
" end;\n",
|
||||||
" end;\n",
|
" end;\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" print(\"User setup done!\")\n",
|
" print(\"User setup done!\")\n",
|
||||||
|
" except Exception as e:\n",
|
||||||
|
" print(f\"User setup failed with error: {e}\")\n",
|
||||||
|
" finally:\n",
|
||||||
" cursor.close()\n",
|
" cursor.close()\n",
|
||||||
" conn.close()\n",
|
" conn.close()\n",
|
||||||
"except Exception as e:\n",
|
"except Exception as e:\n",
|
||||||
" print(\"User setup failed!\")\n",
|
" print(f\"Connection failed with error: {e}\")\n",
|
||||||
" cursor.close()\n",
|
|
||||||
" conn.close()\n",
|
|
||||||
" sys.exit(1)"
|
" sys.exit(1)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user