【Python相關(guān)包版本信息】
Django ? ? ? ? ? ? ? ? ? ? ? ?4.2.7
django-dmPython ? ? ? ? ? ? ? 3.1.7
dmPython ? ? ? ? ? ? ? ? ? ? ?2.5.5
【達夢數(shù)據(jù)庫版本】
DM Database Server 64 V8
DB Version: 0x7000c
適配過程中發(fā)現(xiàn)的問題如下:
錯誤一:django.core.exceptions.ImproperlyConfigured: 'django_dmPython' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3'
解決方法:將django_dmPython和django_dmPython-3.1.7.dist-info復制一份,放到django下面的db/backends/目錄下,因此后面發(fā)現(xiàn)與此包相關(guān)的問題,需要修改2處。
錯誤二-1:ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/python/lib/python3.12/site-packages/django/utils/encoding.py). Did you mean: 'force_bytes'?
修改django/db/backends/django_dmPython/base.py,將18行中的force_text去掉,因為在代碼中沒有被調(diào)用。
###你也可以在django/utils/encoding.py文件中添加此函數(shù),這樣修改后,就可以忽略錯誤二-2、錯誤二-3。
老版本django中的force_text函數(shù)的定義如下:
def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
?? ?warnings.warn(
??????? 'force_text() is deprecated in favor of force_str().',
??????? RemovedInDjango40Warning, stacklevel=2,
??? )
??? return force_str(s, encoding, strings_only, errors)
錯誤二-2:ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/python/lib/python3.12/site-packages/django/utils/encoding.py). Did you mean: 'force_bytes'?
修改django/db/backends/django_dmPython/operations.py文件,將前面的import導入的force_text去掉,同時將下面的調(diào)用修改為force_str(2處)。
錯誤二-3:ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/python/lib/python3.12/site-packages/django/utils/encoding.py). Did you mean: 'force_bytes'?
修改django/db/backends/django_dmPython/utils.py文件,將前面的import導入的force_text去掉,同時將下面的調(diào)用修改為force_str(1處)
錯誤三、ImportError: cannot import name 'Random' from 'django.db.models.expressions' (/usr/local/python/lib/python3.12/site-packages/django/db/models/expressions.py)
老版本django中的Random類的定義如下:
class Random(Expression):
??? output_field = fields.FloatField()
??? def __repr__(self):
??????? return "Random()"
??? def as_sql(self, compiler, connection):
??????? return connection.ops.random_function_sql(), []
修改方法:修改django/db/models/expressions.py文件,在代碼最后面,增加上述定義。(不要嘗試將其加入到django_dmPython/compiler.py,因為上面這個類又調(diào)用了Expression,比較麻煩。)
錯誤四:django.core.exceptions.FullResultSet
解決方法:修改django/db/models/sql/where.py,將175和176行注釋掉(這樣修改肯定不對,不過目前暫未發(fā)現(xiàn)影響,后期發(fā)現(xiàn)了再改)。
錯誤五:AttributeError: 'Query' object has no attribute 'explain_query'
解決方法:修改django_dmPython/compiler.py,將300-304行注釋掉(這樣修改肯定不對,不過目前暫未發(fā)現(xiàn)影響,后期發(fā)現(xiàn)了再改,不過應該影響不大,這個應該是生成explain查詢sql語句性能的動作)。
老版本/django/db/models/sql/query.py代碼中定義了explain_query變量,在Query類中的__init__函數(shù)中定義此變量,賦默認值為False;在函數(shù)explain中將其值修改為了explain了。
錯誤六:Invalid column name [AAAAAAAAAAAAAAAAAC]
這個問題是達夢驅(qū)動的問題,直接按照下面修改就行。
解決方法:修改django_dmPython/operations.py中的last_insert_id函數(shù),參考如下寫法。
def last_insert_id(self, cursor, table_name, pk_name):
??????? """
??????? Given a cursor object that has just performed an INSERT statement into
??????? a table that has an auto-incrementing ID, returns the newly created ID.
??????? This method also receives the table name and the name of the primary-key
??????? column.
??????? """
??????? # sq_name = self._get_sequence_name(table_name)
??????? # cursor.execute('SELECT "%s".currval FROM dual' % sq_name)
??????? if cursor.lastrowid is not None:
??????????? lastrowid=cursor.lastrowid
??????????? rowid_dict = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9,
????????????????????????????????? 'K': 10, 'L': 11,
????????????????????????????????? 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20,
????????????????????????????????? 'V': 21, 'W': 22,
????????????????????? ????????????'X': 23, 'Y': 24, 'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, 'e': 30, 'f': 31,
????????????????????????????????? 'g': 32, 'h': 33,
????????????????????????????????? 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39, 'o': 40, 'p': 41, 'q': 42,
????????????????????????????????? 'r': 43, 's': 44,
????????????????????????????????? 't': 45, 'u': 46, 'v': 47, 'w': 48, 'x': 49, 'y': 50, 'z': 51, '0': 52, '1': 53,
????????????????????????????????? '2': 54, '3': 55,
????????????????????????????????? '4': 56, '5': 57, '6': 58, '7': 59, '8': 60, '9': 61, '+': 62, '/': 63}
??????????? rowid_temp = 0
??????????? for i in lastrowid[-8:]:
??????? ????????rowid_temp = rowid_temp * 64 + rowid_dict[i]
??????????? lastrowid=rowid_temp
??????????? query = 'select %s from %s where rowid = %s' %(self.quote_name(pk_name), self.quote_name(table_name), lastrowid)
??????????? cursor.execute(query)
??????? else:
??????????? cursor.execute('SELECT MAX(%s) from %s' %(self.quote_name(pk_name), self.quote_name(table_name)))
???????????
??????? value = cursor.fetchone()[0]
??????? return value
錯誤七、TypeError: DatabaseSchemaEditor._alter_column_type_sql() takes 5 positional arguments but 7 were given
上圖是新老版本的_alter_column_type_sql的函數(shù)定義,發(fā)現(xiàn)多了2個參數(shù),分別是old_collation, new_collation。這2個參數(shù)在函數(shù)體內(nèi)調(diào)用如下:
可以很容易定位到_collate_sql函數(shù),后面2個參數(shù)壓根未使用,只是使用了collation,也就是new_collation參數(shù),這個函數(shù)的作用是字符集排序;
查看django_dmPython/schema.py中的_alter_column_type_sql函數(shù),在參數(shù)中添加2個參數(shù),這2個參數(shù)暫時先不用,后面有問題再處理(可以參考django/db/backends/postgresql/schema.py或django/db/backends/mysql/schema.py中同名函數(shù)的實現(xiàn)邏輯)。文章來源:http://www.zghlxwxcb.cn/news/detail-861609.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-861609.html
到了這里,關(guān)于arm架構(gòu),django4.2.7適配達夢8數(shù)據(jù)庫的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!