Как получить все таблицы из одной базы данных, если у меня их две?Python

Программы на Python
Anonymous
Как получить все таблицы из одной базы данных, если у меня их две?

Сообщение Anonymous »

У меня две базы данных, и я хочу получить все таблицы только из одной. Если я запускаю cur.execute("SELECT name FROM sqlite_master") и cur.execute("SELECT name FROM sqlite_schema"), оба результата будут одинаковыми и извлекут все таблицы в обеих базах данных. Я хочу получить данные только из одной базы данных.
Полный код:

Код: Выделить всё

import sqlite3

while  True:
con=sqlite3.connect("Nested_Database_try")
cur=con.cursor()
Mcon=sqlite3.connect("Master_Database_try")
Mcur=con.cursor()
print('''            Press "1" for Creating Nested Table (Example:-  Invoice Number)
Press "2" for Creating Master Table (Example:-  DSS Number)
Press "11" Insert Invoice Detail
Press "21" Insert Dss Detail
Press 3 View Invoice Detail
Press 4 View DSS Detail
Press 5 Exit Program\n''')
#print(strings+"\n")
selection=int(input("Choose 1 or 2 for creating tables...   "))

if selection==1:
en1=input("Type Nasted Table Name Like Invoice Number...   ")

#---------This Table is use for invoice Table
Nasted_table=cur.execute('''CREATE TABLE IF NOT EXISTS '{}'(
Product TEXT,
Amount  INT,
Total_amt NT
);'''.format(en1))
print("Nested Table Create Sucessfully as Invoive number with" + en1)
print("---------------------------------------------------------------------------------------\n")

elif  selection==11:
inv_no=input("Enter invoice no...   ")
product=input("Enter Product Name...   ")
amt=input("Enter product amount...   ")
T_amt=input("Enter Total amt...   ")

inset=cur.execute(" INSERT Into '{}' (Product, Amount, Total_amt) values ( '{}',  {},  {}); ".format(inv_no ,product, amt, T_amt))

con.commit()
#con.close()
print("+++++++++++++++++++++++++++++++++++++++++++++++\n")

elif selection==2:
en2=input("Type Master Table Name Like DSS Number...   ")
Master_table=cur.execute('''CREATE TABLE IF NOT EXISTS '{}'(
invoice_no INT);'''.format(en2))
print("Master  Table  Create  Sucessfully as Invoive number with" + en2)
print("===============================================\n")

elif selection==21:
M_inv=input("Enter Total amt...   ")
inset=cur.execute(" INSERT Into '{}' (Product, Amount, Total_amt) values ( {}); ".format(en2 ,M_inv))
Mcon.commit()
#Mcon.close()
print("************************************************************************\n")

elif selection==3:
inv_rec=input("Enter Table / Invoice name...   ")    #---- cur.execute(''' Select name  from sql_master''')
View_Invoice_Detail=cur.execute("SELECT * FROM '{}'; ".format(inv_rec))
for items in View_Invoice_Detail:
print(items)

con.commit()
#con.close()
print("______________________________________________\n")

elif selection==4:
View_DSS_Detail=cur.execute("SELECT name FROM sqlite_master") #---working
View_DSS_Detail=cur.execute("SELECT name FROM sqlite_schema") #--same working as above

for itemss in View_DSS_Detail:
print(itemss)

Mcon.commit()
#Mcon.close()

elif selection==5:
print("Programe closed")
break
Я хочу получить все таблицы только из одной конкретной базы данных.

Подробнее здесь: https://stackoverflow.com/questions/786 ... i-have-two

Вернуться в «Python»