OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Adding into sqlite with class constructors and query

  • Thread starter Thread starter Adi
  • Start date Start date
A

Adi

Guest
Below is my class constructor for eventages class EventAges: def init(self, EventAgeName, EventAgeStart, EventAgeEnd): self.EventAgeName = EventAgeName self.EventAgeStart = EventAgeStart self.EventAgeEnd = EventAgeEnd

And this is my func def add_event_ages(self, event_ages): query = '''INSERT INTO EventAges (EventAgeId, EventAgeName, EventAgeStart, EventAgeEnd) VALUES ( ?, ?, ?)''' values = ( event_ages.EventAgeName, event_ages.EventAgeStart, event_ages.EventAgeEnd) self.cursor.execute(query, values) self.connection.commit() EventAgeId = self.cursor.lastrowid return EventAgeId

In the database, my fields for EventAges include its Id but I did not include it in my class constructor, since it is already autoincremented, The problem now is when querying to get the event ages since i also wantt to retrieve the EventAgesId but it is not accepted because it is not in the class constructor

So is there any way for me to include eventagesId in the class constructor while also not needing to manually add the Id when inserting into table

I tried to include event ages Id in the constructor and remove it in the query but it doesnt run since it wants the event ages Id to also be added, Im still not well versed in python with sqlite so Ive been having a hard time with this
<p>Below is my class constructor for eventages
class EventAges:
def <strong>init</strong>(self, EventAgeName, EventAgeStart, EventAgeEnd):
self.EventAgeName = EventAgeName
self.EventAgeStart = EventAgeStart
self.EventAgeEnd = EventAgeEnd</p>
<p>And this is my func
def add_event_ages(self, event_ages):
query = '''INSERT INTO EventAges (EventAgeId, EventAgeName, EventAgeStart, EventAgeEnd) VALUES ( ?, ?, ?)'''
values = ( event_ages.EventAgeName, event_ages.EventAgeStart, event_ages.EventAgeEnd)
self.cursor.execute(query, values)
self.connection.commit()
EventAgeId = self.cursor.lastrowid
return EventAgeId</p>
<p>In the database, my fields for EventAges include its Id but I did not include it in my class constructor, since it is already autoincremented,
The problem now is when querying to get the event ages since i also wantt to retrieve the EventAgesId but it is not accepted because it is not in the class constructor</p>
<p>So is there any way for me to include eventagesId in the class constructor while also not needing to manually add the Id when inserting into table</p>
<p>I tried to include event ages Id in the constructor and remove it in the query but it doesnt run since it wants the event ages Id to also be added, Im still not well versed in python with sqlite so Ive been having a hard time with this</p>
 
Top