本帖最后由 We. 于 2020-4-17 22:19 编辑
小白自学python ,最近在倒腾sql数据库。根据教程一步一步来的,不知道错哪里了。
大佬帮忙看看。
[Python] 纯文本查看 复制代码 #coding=utf-8
import pymssql
class MSSQL:
def __init__(self, host, user, pwd, db):
self.host = host
self.user = user
self.pwd = pwd
self.db = db
def __GetConnect(self):
if not self.db:
raise (NameError, '没有设置数据库信息')
self.conn = pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset="utf-8")
cur = self.conn.cursor()
if not cur:
raise (NameError, '链接数据库失败')
else:
return cur
def ExeQuery(self,sql):
cur = self.__GetConnect()
cur.execute(sql)
relist = cur.fetchall(sql)
self.conn.close()
return reslist
def main():
ms = MSSQL(host="localhost", user="sa", pwd="", db="Inventory")
reslist = ms.ExeQuery("select * from Inventory")
for row in reslist:
print(row)
if __name__ == '__main__':
main()
然后报错的信息有点多给我看蒙了。
[Python] 纯文本查看 复制代码 C:\Users\admin\AppData\Local\Programs\Python\Python38\python.exe C:/Users/admin/PycharmProjects/untitled/car.py
C:/Users/admin/PycharmProjects/untitled/car.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
import pymssql
Traceback (most recent call last):
File "src\pymssql.pyx", line 636, in pymssql.connect
File "src\_mssql.pyx", line 1957, in _mssql.connect
File "src\_mssql.pyx", line 676, in _mssql.MSSQLConnection.__init__
File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (20010, b'DB-Lib error message 20010, severity 8:\nUnable to allocate sufficient memory (localhost:1433)\nOperating System error during No error (12)\n')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/admin/PycharmProjects/untitled/car.py", line 34, in <module>
main()
File "C:/Users/admin/PycharmProjects/untitled/car.py", line 30, in main
reslist = ms.ExeQuery("select * from Inventory")
File "C:/Users/admin/PycharmProjects/untitled/car.py", line 22, in ExeQuery
cur = self.__GetConnect()
File "C:/Users/admin/PycharmProjects/untitled/car.py", line 14, in __GetConnect
self.conn = pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset="utf-8")
File "src\pymssql.pyx", line 642, in pymssql.connect
pymssql.OperationalError: (20010, b'DB-Lib error message 20010, severity 8:\nUnable to allocate sufficient memory (localhost:1433)\nOperating System error during No error (12)\n')
进程已结束,退出代码 1
如果是单纯敲代码能实现需求,但是一到面对对象我就歇菜了,底子薄弱了些。 |