def get_text(self): global cursor if self.error == True: return '' date = self.get_datetime().date() cursor.execute("SELECT format_date(%s)", (date, )) return cursor.fetchone()[0]
def unique(part): cursor.execute('''SELECT b.ThreadDiameterID FROM [LocknutData].[dbo].[PartNumber] a INNER JOIN [LocknutData].[dbo].[Pitch2ThreadDiameter] b on b.Pitch2ThreadDiameterID = a.Pitch2ThreadDiameterID WHERE a.Name = '{}';'''.format(part)) return cursor.fetchone()[0] cursor.close()
def getid(pitch): sql = '''INSERT INTO LocknutData.dbo.Pitch ([Name]) SELECT %s WHERE NOT EXISTS (SELECT 1 FROM LocknutData.dbo.Pitch WHERE [Name] = '%s');''' % (pitch, pitch) cursor.execute(sql) cursor.execute('''SELECT PitchID FROM LocknutData.dbo.Pitch WHERE Name = '{}';'''.format(pitch)) return cursor.fetchone()[0] cursor.close()
def getid(designation): cursor.execute('''SELECT PitchThreadDiameterDesignationID FROM LocknutData.dbo.PitchThreadDiameterDesignation WHERE Name = '{}';'''.format(designation)) if cursor.rowcount == 0: cursor.execute( '''INSERT INTO LocknutData.dbo.PitchThreadDiameterDesignation (Name) VALUES ('{}');'''.format(designation)) cursor.commit() cursor.execute('''SELECT PitchThreadDiameterDesignationID FROM LocknutData.dbo.PitchThreadDiameterDesignation WHERE Name = '{}';'''.format(designation)) return cursor.fetchone()[0] cursor.close()
def name(part): # type: (object) -> object """ :rtype: object """ cursor.execute('''SELECT c.[Name] FROM [LocknutData].[dbo].[PartNumber] a INNER JOIN [LocknutData].[dbo].[Pitch2ThreadDiameter] b on b.Pitch2ThreadDiameterID = a.Pitch2ThreadDiameterID INNER JOIN [LocknutData].[dbo].[ThreadDiameter] c on c.ThreadDiameterID = b.ThreadDiameterID WHERE a.Name = '{}';'''.format(part)) return cursor.fetchone()[0] cursor.close()
def getid(dia): cursor.execute('''SELECT ThreadDiameterID FROM LocknutData.dbo.ThreadDiameter WHERE Name = '{}';'''.format(dia)) if cursor.rowcount == 0: if dia[:1] == 'M': unit = 5 eqv = float(dia[1:]) * 0.0393701 else: unit = 4 eqv = mixed_to_float(dia) cursor.execute('''INSERT INTO LocknutData.dbo.ThreadDiameter (Name, MeasurementUnitID, InchMeasurementEquivalent) VALUES ('{}', {}, {});'''.format( dia, unit, eqv)) cursor.execute('''SELECT ThreadDiameterID FROM LocknutData.dbo.ThreadDiameter WHERE Name = '{}';'''.format(dia)) return cursor.fetchone()[0] cursor.close()
def relateid(diametername, pitchname): """ :type diametername: object :type pitchname: object """ tid = diameter.getid(diametername) pid = pitch.getid(pitchname) cursor.execute('''SELECT Pitch2ThreadDiameterID FROM LocknutData.dbo.Pitch2ThreadDiameter WHERE PitchID = %i AND ThreadDiameterID = %i''' % (pid, tid)) if cursor.rowcount == 0: cursor.execute('''INSERT INTO LocknutData.dbo.Pitch2ThreadDiameter (PitchID, ThreadDiameterID) VALUES (%i, %i);''' % (pid, tid)) cursor.commit() cursor.execute('''SELECT Pitch2ThreadDiameterID FROM LocknutData.dbo.Pitch2ThreadDiameter WHERE PitchID = %i AND ThreadDiameterID = %i''' % (pid, tid)) return cursor.fetchone()[0]
def day_selected(self, calendar, date_label, fiscal_label, override): global cursor date_time = self.get_datetime() cursor.execute( "SELECT id FROM fiscal_years " "WHERE active = True AND %s >= start_date " "AND %s <= end_date", (date_time, date_time)) if cursor.fetchone() == None and override == False: fiscal_label.show() date_string = '' date_label.hide() self.error = True if self.timeout == None: self.timeout = GLib.timeout_add_seconds(2, self.force_show) else: date_string = datetime.strftime(date_time, "%m-%d-%Y") date_label.show() self.error = False if self.timeout != None: fiscal_label.hide() GLib.source_remove(self.timeout) self.timeout = None date_label.set_label(str(date_string)) self.emit('day-selected')
def units(dia): cursor.execute('''SELECT MeasurementUnitID FROM LocknutData.dbo.ThreadDiameter WHERE Name = '{}';'''.format(dia)) return cursor.fetchone()[0] cursor.close()