I'm writing an application in Python and I'm using the Adodbapi package to handle my sql queries. For one part of the code, I need to communicate with an Access '97 (no, it's not a typo) database, and I want to get a list of the table names via an SQL statement. I've tried a bunch of statements using MSysObjects but I run into permissions isssues - no I don't have the option of opening the db in access and changing the permissions. I would imagine that Adodbapi has a way of accessing Schema information but I can't manage to find it.
Thanks in advance for your help.
Related
I have basic csv report that is produced by other team on a daily basis, each report has 50k rows, those reports are saved on sharedrive everyday. And I have Oracle DB.
I need to create autoscheduled process (or at least less manual) to import those csv reports to Oracle DB. What solution would you recommend for it?
I did not find such solution in SQL Developer, since it is upload from file and not a query. I was thinking about python cron script, that will autoran on a daily basis and transform csv report to txt with needed SQL syntax (insert into...) and then python will connect to Oracle DB and will ran txt file as SQL command and insert data.
But this looks complicated.
Maybe you know other solution that you would recommend yo use?
Create an external table to allow you to access the content of the CSV as if it were a regular table. This assumes the file name does not change day-to-day.
Create a scheduled job to import the data in that external table and do whatever you want with it.
One common blocking issue that prevents using 'external tables' is that external tables require the data to be on the computer hosting the database. Not everyone has access to those servers. Or sometimes the external transfer of data to that machine + the data load to the DB is slower than doing a direct path load from the remote machine.
SQL*Loader with direct path load may be an option: https://docs.oracle.com/en/database/oracle/oracle-database/19/sutil/oracle-sql-loader.html#GUID-8D037494-07FA-4226-B507-E1B2ED10C144 This will be faster than Python.
If you do want to use Python, then read the cx_Oracle manual Batch Statement Execution and Bulk Loading. There is an example of reading from a CSV file.
I know there are ways of storing data/tables from one server to another, such as the instruction provided here. However, due to I use python to scrape, create, and store data, I am wondering that whether I could fulfill this process by directly using SQLAlchemy. More precisely, after I store the scraped data in the database I create through SQLAlchemy in my own computer, can I simultaneously store.copy those database/tables to another computer/server directly through SQLAlchemy? Can anyone help? Thanks so much.
I want to dump oracle objects like tables and stored procedures using cx_Oracle from python ,
is any tutorial how to do this ?
If you are looking for the source code for tables you can use the following:
select DBMS_METADATA.GET_DDL('TABLE','<table_name>') from DUAL;
for stored procedures you can use
select text from all_source where name = '<procedure name>'
In general this is not a cx_Oracle specific problem, just call the oracle specific tables (like all_source) or functions (like get_ddl) and read it in like any other query. There are more of these sorts of tables (like user_source for source that you the specific user own) in Oracle, but I'm doing this off the top of my head and don't have easy access to an Oracle db to remind myself.
I would like to copy the contents of a MySQL database from one server to another using a third server. This could be done from the shell prompt using this:
mysqldump --host=hostname1 --user=username --password="mypwd" acme | mysql --host=hostname2 --user=username --password="mypwd" acme
However, how do I do this from within a Python script without using os.system or any of the other subprocess methods? I've read through the MySQLdb docs, but don't see a way to do a bulk export/import. Thank you!
If you dont want to use mysqldump from the command line (using the os.system methods) you are kind of tied to get the data straight from MySQL and then put it to the other server. In that respect your question looks very similar to Get Insert Statement for existing row in MySQL
you can use a query to get the schema creation sql
SHOW CREATE TABLE MyTable;
And then you need to implement a script that just querys data and inserts it to the other server.
You could also look into third party applications that allows you to copy data from one database to another.
I have my database in msacess 2000 .mdb format which I downloaded from the net and now I want to access that database from my program which is a python script.
Can I call tables from my programs??
it would be very grateful if anyone of you please suggest me what to do
For whoever pass by, another option is using mdbtools - which can export the MDB database to a re-usable format, like CSV- check: http://mazamascience.com/WorkingWithData/?p=168
If you don't need to update the mdb file, just to import legacy data, doing something akin to the recipe on the link above is easier than get pyodbc working properly and, it does not require access to a Windows machinne
If you work on Windows, then you can use ODBC and use odbc module (ActiveState Python has it by default, this is part of win32 extensions), or pyodbc module. Have a look at answers to: How to connect pyodbc to an Access (.mdb) Database file
If you use Jython you can use JDBC-ODBC bridge:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
db = DriverManager.getConnection('jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Nwind.mdb', usr, passwd)
Create an ODBC DSN wit hthis MDB. Python can access ODBC data sources.