3)编程实现在SOLite中使用MyHelper的帮助类获取数据库表information中的account和password 两个字段的数据。
时间: 2023-12-07 21:40:06 浏览: 71
以下是使用MyHelper帮助类获取SOLite数据库表information中account和password字段数据的Python代码示例:
```python
import sqlite3
# 定义MyHelper帮助类
class MyHelper:
def __init__(self, dbname):
self.conn = sqlite3.connect(dbname)
self.cursor = self.conn.cursor()
def __del__(self):
self.cursor.close()
self.conn.close()
def execute(self, sql):
self.cursor.execute(sql)
self.conn.commit()
def fetchall(self, sql):
self.cursor.execute(sql)
return self.cursor.fetchall()
# 创建MyHelper对象
helper = MyHelper('test.db')
# 获取information表中account和password字段数据
result = helper.fetchall('SELECT account, password FROM information')
# 输出结果
for row in result:
print(row[0], row[1])
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)