docs: def create_insert_dict_string(self, tblname, d, PKfields=[], fields=None, check_existing = False):
          '''The main function of the insert_dict functions.
             This creates and returns the SQL query and parameters used by the other functions but does not insert any data into the database.
  
             Simple function for inserting a dictionary whose keys match the fieldnames of tblname. The function returns two values, the
             second of which is a dict containing the primary keys of the record. If a record already exists then no insertion is performed and
             (False, the dictionary of existing primary keys) is returned. Otherwise, the record is inserted into the database and (True, d)
             is returned.'''
  
          if type(PKfields) == type(""):
              PKfields = [PKfields]
  
          if fields == None:
              fields = sorted(d.keys())
          values = None
          SQL = None
          try:
              # Search for existing records
              wherestr = []
              PKvalues = []
              for PKfield in PKfields:
                  if d[PKfield] == None:
                      wherestr.append("%s IS NULL" % PKfield)
                  else:
                      wherestr.append("%s=%%s" % PKfield)
                      PKvalues.append(d[PKfield])
              PKfields = join(PKfields, ",")
              wherestr = join(wherestr, " AND ")
  
              record_exists = None
              if check_existing:
                  record_exists = not(not(self.execute_select("SELECT %s FROM %s" % (PKfields, tblname) + " WHERE %s" % wherestr, parameters=tuple(PKvalues), locked = False)))
  
              SQL = 'INSERT INTO %s (%s) VALUES (%s)' % (
              tblname, join(fields, ", "), join(['%s' for x in range(len(fields))], ','))
              values = tuple([d[k] for k in fields])
              return SQL, values, record_exists
          except Exception, e:
              raise Exception("Error occurred during database insertion: '%s'. %s" % (str(e), traceback.format_exc()))