பைத்தானில் C++ நிரல்களை இறக்கம் செய்தல் - பல அட்டவணைகளைப் பயன்படுத்தி வினவல் | 12th Computer Science : Chapter 15 : Integrating Python with MySql and C++ : Data Manipulation Through SQL
பல அட்டவணைகளைப் பயன்படுத்தி வினவல்
ஒன்றுக்கு மேற்பட்ட அட்டவணைகளைச் சேர்த்து பைத்தானில் வினவலை
மேற்கொள்ள முடியும். பின்வரும் எடுத்துக்காட்டில் மாணவர்களின் Rollno, Duty, Age ஆகிய
விவரங்களைக் கொண்ட "Appointments” அட்டவணையை உருவாக்குவோம். "student” மற்றும்
"Appointments” அட்டவணைகளை ஒன்றிணைத்து நெடுவரிசையின் தலைப்புக்களுடன் கூடிய இறுதி
அட்டவணையைக் காணலாம்.
எடுத்தக்காட்டு 15.11-1
import sqlite3
connection =
sqlite3.connect("Academy.db")
cursor = connection.cursor()
cursor.execute("""DROP
TABLE Appointment;""")
sql_command = ""'"|
CREATE TABLE
Appointment ( rollnointprimarkey, Dutyvarchar(10), age int )''''
cursor.execute(sql_command)
sql_command ="""INSERT
INTO Appointment (Rollno,Duty ,age )
VALUES ("1",
"Prefect", "17");"'"
cursor.execute(sql_command)
sql_command =
""'"INSERT INTO Appointment (Rollno, Duty, age)
VALUES ("2",
"Secretary", "16");"""
cursor.execute(sql_command)
# never forget this, if you want the
changes to be saved:
connection.commit()
cursor.execute("SELECT student.rollno,student.sname,Appointment.
Duty,Appointment.Age FROM
student,Appointment where student.
rollno=Appointment.rollno")
#print (cursor.description) to display
the field names of the table
co = [i[0] for i in
cursor.description]
print(co)
# Field informations can be read from
cursor.description.
result = cursor.fetchall()
for r in result:
print(r)
வெளியீடு
('Rollno', 'Sname', 'Duty', 'age']
(1, 'Akshay', 'Prefect', 17)
(2, 'Aravind', 'Secretary', 16)
குறிப்பு
cursor.description
ஒவ்வொரு நெடுவரிசையின் தலைப்புகளின் விவரங்களைக் கொண்டிருக்கும். இது பதிவாக சேமிக்கப்படும்.
முதல் பதிவு நெடுவரிசையின் பெயர்கைளக் குறிக்கும் (index=0) இதை பயன்படுத்தி அட்டவணையின்
புலங்களின் பெயர்களைக் காண்பிக்க முடியும்.