def insertListingInDatabase(self):
        values  = []

        id = db.select_sql(self.databaseConnection, "SELECT MAX(listing_id) FROM Listing", "Select biggest listing_id")[0][0] + 1
        values.append("{}".format(id))

        tempName = self.insertListingNameEntry.get()[:250]
        if (len(tempName) <= 0):
            values.append("id : {}".format(id))
        else:
            values.append(tempName)

        tempSummary = self.insertListingSummaryEntry.get()[:65000]
        if (len(tempSummary) <= 0):
            values.append("There is no summary for this listing.")
        else:
            values.append(tempSummary)

        values.append(self.insertListingAccomodatesScale.get())
        values.append(self.insertListingSquareFeetScale.get())
        values.append(self.insertListingPriceScale.get())
        values.append(self.listingHostId)
        values.append(self.listingNeighbourhoodId)
        values.append(self.insertListingIsBusinessTravelReady.get())
        values.append(self.propertyTypeIdDict[self.insertListingPropertyTypeId.get()])
        values.append(self.roomTypeIdDict[self.insertListingRoomTypeId.get()])
        values.append(self.bedTypeIdDict[self.insertListingBedTypeId.get()])
        values.append(self.cancellationPolicyIdDict[self.insertListingCancellationPolicyId.get()])

        db.insert_listing(self.databaseConnection, values)
        self.updateDatabaseVariables()
        self.insertFrame.grid_slaves(row=5, column=8)[0].grid_forget()
        self.insertFrame.grid_slaves(row=6, column=8)[0].grid_forget()
        self.drawInsert()
 def getNeighbourhoodIdForCityIdDict(self, cityId):
     try:
         result = dict(db.select_sql(self.databaseConnection,
                                     st.select_neighbourhood_names_ids_for_city_id_statements.format(cityId),
                                     "Select Neighbourhood names and ids for city {}".format(cityId)))
     except:
         result = {"None": 0}
     finally:
         return result
 def getNeighbourhoodIdDict(self):
     try:
         result = dict(db.select_sql(self.databaseConnection,
                                     st.select_neighbourhood_names_ids_statements,
                                     "Select Neighbourhood names and ids"))
     except:
         result = {"None": 0}
     finally:
         return result
 def getBedTypeIdDict(self):
     try:
         result = dict(db.select_sql(self.databaseConnection,
                                     st.select_bed_type_names_ids_statements,
                                     "Select Bed_type names and ids"))
     except:
         result = {"None": 0}
     finally:
         return result
 def getCityIdDict(self):
     try:
         result = dict(db.select_sql(self.databaseConnection,
                                     st.select_city_names_ids_statements,
                                     "Select City names and ids"))
     except:
         result = {"None": 0}
     finally:
         return result
 def getReviewScoresRatingMinMax(self):
     try:
         result = db.select_sql(self.databaseConnection,
                       st.select_listing_review_score_rating_min_max,
                       "Select Listing review_scores_rating min and max")[0]
     except:
         result = (0, 0)
     finally:
         return result
 def getPriceMinMax(self):
     try:
         result = db.select_sql(self.databaseConnection,
                                st.select_listing_price_min_max,
                                "Select Listing price min and max")[0]
     except:
         result = (0, 0)
     finally:
         return result
 def getSquareFeetMinMax(self):
     try:
         result = db.select_sql(self.databaseConnection,
                                st.select_listing_sqare_feet_min_max,
                                "Select Listing square_feet min and max")[0]
     except:
         result = (0, 0)
     finally:
         return result
 def getAccommodatesMinMax(self):
     try:
         result = db.select_sql(self.databaseConnection,
                                st.select_listing_accomodates_min_max,
                                "Select Listing accommodates min and max")[0]
     except:
         result = (0, 0)
     finally:
         return result
    def checkNeighboorhood(self):
        if (len(self.insertListingNeighbourhood.get()) > 0):
            self.insertListingCheckNeighboorhoodButton["state"] = DISABLED
            if (self.insertListingCheckHostButton["state"] == DISABLED):
                self.insertButton["state"] = NORMAL

            values = (self.insertListingNeighbourhood.get(),
                      self.cityIdDict[self.insertListingNeighbourhoodCity.get()])

            result = db.select_sql_with_values(self.databaseConnection,
                                               st.find_neighbourhood, (values),
                                               "Check Neighbourhood")
            if (len(result) == 1):
                self.listingNeighbourhoodId = result[0][0]
            else:
                self.listingNeighbourhoodId = db.select_sql(self.databaseConnection, "SELECT MAX(neighbourhood_id) FROM Neighbourhood", "Select biggest neighbourhood_id")[0][0] + 1
                values = [self.listingNeighbourhoodId, self.insertListingNeighbourhood.get(), self.cityIdDict[self.insertListingNeighbourhoodCity.get()]]
                db.insert_neighboorhood(self.databaseConnection, values)

            Label(self.insertFrame, text="id : {}".format(self.listingNeighbourhoodId)).grid(row=6, column=8, sticky=W, padx=5, pady=5)
    def executePredefinedQuery(self):
        sql = st.predefined_queries[self.predefniedQuery.get()]

        queryResults = db.select_sql(self.databaseConnection, sql, "Execute predefined query")

        self.showResults(queryResults, sql, None)