I have two database and want to fetching all tables in only one database. If i run these commands
cur.execute("SELECT name FROM sqlite_master")
and
cur.execute("SELECT name FROM sqlite_schema")
both result are same and fetching all tables in all databases. I want to fetch only from one database.
full cade is here
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 Programn''')
#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
I want to fetch all tables only from one spacific database.
Thank for help in Advance