'INSERT the document (with valid columns) in the database.'

def db_insert(self):

    if (not self.name):
        set_new_name(self)
    if (not self.creation):
        self.creation = self.modified = now()
        self.created_by = self.modifield_by = frappe.session.user
    d = self.get_valid_dict()
    columns = d.keys()
    try:
        frappe.db.sql(u'insert    into    `tab{doctype}`\n DCTB  DCTB  DCTB  DCTB ({columns})    values    ({values})'.format(doctype=self.doctype, columns=u',    '.join([((u'`' + c) + u'`') for c in columns]), values=u',    '.join(([u'%s'] * len(columns)))), d.values())
    except Exception as e:
        if (e.args[0] == 1062):
            if (u'PRIMARY' in cstr(e.args[1])):
                if (self.meta.autoname == u'hash'):
                    self.name = None
                    self.db_insert()
                    return
                frappe.msgprint(_(u'Duplicate    name    {0}    {1}').format(self.doctype, self.name))
                traceback = sys.exc_info()[2]
                raise_(frappe.DuplicateEntryError, (self.doctype, self.name, e), traceback)
            elif (u'Duplicate' in cstr(e.args[1])):
                self.show_unique_validation_message(e)
            else:
                raise
        else:
            raise
    self.set(u'__islocal', False)
