为什么必须同时安装Pyodbc和django-pyodbc-azure才能与Django的最新SQL Server版本对接? django为什么不能开箱即用使用Pyodbc?我在让Sql Server与python 3.4.5,Django 2.1,pyodbc 4.0+和Django-Pyodbc-azure 2.0.8兼容方面遇到麻烦。尝试查询用inspectdb反映的某些模型时,总是出现分段错误。
我正在使用的linux版本是openSUSE 42.1 我正在使用的Sql Server版本是2014。
答案 0 :(得分:1)
//...
private lateinit var context: Context
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): ViewHolder {
context = parent.context
val view = LayoutInflater.from(context)
.inflate(R.layout.date_card, parent, false)
return ViewHolder(view)
}
override fun getItemCount() = data.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dateItem = data[position]
with(holder.itemView) {
tv_day.text = dateItem.getDayOfMonth()
tv_day2.text = dateItem.getDayName(resources)
rv_overview.apply {
layoutManager = LinearLayoutManager(this@DateAdapter.context)
adapter = PlanAdapter(dateItem.planItems)
setHasFixedSize(false)
}
}
}
是Django引擎,它将Django ORM方法转换为原始SQL(以及其他功能)。 django-pyodbc-azure
允许Python通过pyodbc
使用特定于数据库的驱动程序对数据库运行原始SQL查询。所有数据库后端均是如此。他们同时具有Django引擎和Python包。例如,在PostgreSQL中,它使用了随附的Django unixODBC
引擎,该引擎可与postgresql
Python软件包一起使用。
在SQL Server的堆栈中,psycopg2
通过pyodbc
与unixODBC
或freetds
Microsoft驱动程序进行通信。翻译有几层。
从Web服务器到SQL Server的数据库服务器的堆栈:
msodbc
:将Django的ORM方法转换为原始SQL。django-pyodbc-azure
:从Python桥接到unixODBC pyodbc
库,用于在* nix上进行ODBC通信。unixODBC
或freetds
:驱动程序从unixODBC到SQL Server的桥接。