Hi,
I'm trying to import a csv file into a dal database outside web2py and
I'm not able to import values into the referring columns of the database.
In my code there are 4 tables created and I'm fetching data from the single
csv file into the tables, but when a column of a table is referring to
another table it is not fetching anything.
I'm trying to separately fetch the data into the referring column but not
able to figure out the correct syntax or method.
Can someone please help me with this..?
[I've attached my code to this post, kindly find the code and let me know
how to go about it.]
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
#Creating Database
db2.define_table('location1',
Field('country'),
Field('state1'),
Field('city'),
format= '%(city)s')
db2.define_table('educational_inst',
Field('name',length=100,writable=True,readable=True),
Field('address',length=300,writable=True,readable=True),
Field('phone_no',length=100,writable=True,readable=True),
Field('email_id',length=100,writable=True,readable=True),
Field('loc','reference location1'),
Field('university',length=100,writable=True,readable=True),
Field('accomodation',length=100,requires = IS_IN_SET(('hostel','own-arrangements'))),
Field('body',length=300,writable=True,readable=True),format='%(name)s')
db2.define_table('course',
Field('course_name',length=100,requires = IS_IN_SET(('BE','BTech','ME','Mtech','BSc','BA','Bcom','MBA','MCA','LLB'))),
Field('course_level',requires=IS_IN_SET(('UG','PG','Diploma','Part-Time','Full-Time','Certification-Course'))),
Field('course_duration',length=100,writable=True,readable=True),format='%(course_name)s')
db2.define_table('edu_course',
Field('EID','reference educational_inst',readable=False),
Field('CID','reference course',readable=False),
Field('Fees',length=300,writable=True,readable=True),
Field('Intake',length=300,writable=True,readable=True),primarykey=['EID','CID'],format='%(name)s %(course_name)s')
def csv_read(filename):
filechannel = open(filename, 'rb')
filedata = csv.reader(filechannel)
return filedata
print "Print Data from CSV file"
filename = "sarathy.csv"
reader = csv_read(filename)
cityarray = []
namearray = []
coursearray = []
for row in reader:
if row[3] in cityarray:
if (row[5] in namearray ) or (row[14] in coursearray):
print "No Insert"
else:
print "Success"
db2.educational_inst.insert(name=row[5], address=row[6], phone_no=row[7], email_id=row[8], accomodation=row[10], university=row[11], body=row[12])
namearray.append(row[5])
db2.course.insert(course_name=row[14], course_level=row[15], course_duration=row[16])
coursearray.append(row[14])
print "No Insert"
else:
print "Success"
db2.location1.insert(country=row[1], state1=row[2], city=row[3])
cityarray.append(row[3])
print coursearray
print cityarray
print namearray
rows = db2.location1
for row in reader:
var1= db2.select('SELECT db2.location1.id FROM db2.location1 WHERE db2.location1.city== rows[3]')
db2.educational_inst.insert(loc=var1)
db2.commit()
,country,state,city,,edu_name,edu_address,edu_phone,edu_email,loc,edu_acc,edu_univ,edu_desc,,course_name,course_level,course_duration(Months),EID,CID,course_fees(PA),course_intake
,India,KA,BLR,,MSRIT,Mathikere,080-236589,[email protected],,Yes,VTU,Good college,,BSc,UG,36,,,25000,50
,India,KA,BLR,,MSRIT,Mathikere,080-236588,[email protected],,Yes,VTU,Good college,,MCA,PG,24,,,50000,25
,India,KA,BLR,,MSRIT,Mathikere,080-236587,[email protected],,Yes,VTU,Good college,,BE,UG,48,,,25000,60
,India,KA,BLR,,MSRIT,Mathikere,080-236586,[email protected],,Yes,VTU,Good college,,MBA,PG,24,,,100000,30
,India,KA,BLR,,MSRIT,Mathikere,080-236585,[email protected],,Yes,VTU,Good college,,BCom,UG,36,,,25000,50
,India,KA,BLR,,MSRIT,Mathikere,080-236584,[email protected],,Yes,VTU,Good college,,BA,UG,36,,,25000,50
,India,KA,BLR,,UVCE,Kempe Gowda Circle,[email protected],080-261618,,Yes,Autonomous,Reputed College,,BE,UG,48,,,20000,80
,India,KA,BLR,,UVCE,Kempe Gowda Circle,[email protected],080-261617,,Yes,Autonomous,Reputed College,,M.Tech,PG,24,,,60000,30
,India,KA,BLR,,UVCE,Kempe Gowda Circle,[email protected],080-261616,,Yes,Autonomous,Reputed College,,B.Arch,UG,60,,,30000,40
,India,KA,BLR,,UVCE,Kempe Gowda Circle,[email protected],080-261615,,Yes,Autonomous,Reputed College,,M.Arch,PG,24,,,60000,20
,India,KA,MYS,,SJCIT,Sidhartha Nagar,[email protected],082-2818191,,Yes,VTU,Good college,,BE,UG,48,,,20000,80
,India,KA,MYS,,SJCIT,Sidhartha Nagar,[email protected],082-2818190,,Yes,VTU,Good college,,M.Tech,PG,24,,,60000,30
,India,KA,MYS,,SJCIT,Sidhartha Nagar,[email protected],082-2818189,,Yes,VTU,Good college,,B.Arch,UG,60,,,30000,40
,India,KA,MYS,,SJCIT,Sidhartha Nagar,[email protected],082-2818188,,Yes,VTU,Good college,,M.Arch,PG,24,,,60000,20
,India,KA,BLG,,VTU,JnanaBharati,www.vtu.ac.in,91-9779940055,,Yes,Autonomous,Good college,,BE,UG,48,,,20000,80
,India,KA,BLG,,VTU,JnanaBharati,www.vtu.ac.in,91-1190005462,,Yes,Autonomous,Good college,,M.Tech,PG,24,,,60000,30
,India,KA,BLG,,VTU,JnanaBharati,www.vtu.ac.in,91-1190005461,,Yes,Autonomous,Good college,,B.Arch,UG,60,,,30000,40
,India,KA,BLG,,VTU,JnanaBharati,www.vtu.ac.in,91-1190005460,,Yes,Autonomous,Good college,,M.Arch,PG,24,,,60000,20