瀏覽代碼

Validate length of fieldname

version-14
Nabin Hait 8 年之前
父節點
當前提交
d070f880e2
共有 1 個檔案被更改,包括 4 行新增1 行删除
  1. +4
    -1
      frappe/model/db_schema.py

+ 4
- 1
frappe/model/db_schema.py 查看文件

@@ -102,6 +102,9 @@ class DbTable:
columns += self.columns.values() columns += self.columns.values()


for col in columns: for col in columns:
if len(col.fieldname) >= 64:
frappe.throw(_("Fieldname is limited to 64 characters"))
if col.fieldtype in type_map and type_map[col.fieldtype][0]=="varchar": if col.fieldtype in type_map and type_map[col.fieldtype][0]=="varchar":


# validate length range # validate length range
@@ -112,7 +115,7 @@ class DbTable:
try: try:
# check for truncation # check for truncation
max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\ max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\
.format(fieldname=col.fieldname, doctype=self.doctype))
.format(fieldname=col.fieldname, doctype=self.doctype), debug=1)


except MySQLdb.OperationalError, e: except MySQLdb.OperationalError, e:
if e.args[0]==1054: if e.args[0]==1054:


Loading…
取消
儲存