首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏小徐学爬虫

    Pymysql cur.fetchall() 返回 None

    如果 cur.fetchall() 返回 None,可能是由于以下多种问题导致的。 预期在下一个循环中,cur.fetchall() 方法应该返回一个包含所有表名的元组,其中应该包括新创建的表。但实际上,cur.fetchall() 方法却返回了 None。 这样就可以将创建表的更改持久化到数据库中,并在下一个循环中使用 cur.fetchall() 方法查询到新创建的表。 避免多次调用 fetchall():确保只调用一次 fetchall(),并将结果保存以便后续使用。 通过这些步骤,我们可以排查 pymysql 中 cur.fetchall() 返回 None 的问题。

    57610编辑于 2024-10-09
  • 来自专栏Web技术布道师

    PHP PDO fetch 模式各种参数的输出结果一览

    NAMES 'utf8';"); $data = $dbAdapter->query(" SELECT id, name, method FROM category ")->fetchAll ), ) */ $data = $dbAdapter->query(" SELECT name, method FROM category ")->fetchAll 热映中', ) */ $data = $dbAdapter->query(" SELECT id, name, method FROM category ")->fetchAll ), ) */ $data = $dbAdapter->query(" SELECT method, id, name FROM category ")->fetchAll ), ) */ $data = $dbAdapter->query(" SELECT id, name, method FROM category ")->fetchAll

    1.4K30发布于 2019-07-25
  • 来自专栏龙进的专栏

    pymysql查询数据

    我们可以用fetchone来获取一行数据,也可以用fetchall来获取多条数据 在查询数据时,我们可以把指针设置为DictCursor,那么返回的就是一个字典,方便处理。 注意的是,fetchone和fetchall都是返回当前指针位置以后的数据,也就是说,不会返回指针位置之前的数据。 我们可以通过scroll方法来移动指针。 看看下面这段代码,当第一次输出完所有的数据之后,再次执行fetchall,输出的是空列表,只有当指针的位置移动到0之后,才会输出完整的列表。 () print('fetchall') pprint.pprint(result) result = cursor.fetchall() print('fetchall') pprint.pprint (result) cursor.scroll(0, mode='absolute') result = cursor.fetchall() print('fetchall') pprint.pprint

    1.5K20编辑于 2022-10-31
  • 来自专栏AustinDatabases

    PostgreSQL 通过PYTHON 程序查看PG 配置服务运行情况

    None #获取当前PG参数 cur = conn.cursor() cur.execute("""show shared_buffers;""") rows = cur.fetchall ___________________") print(row) cur.execute("""show max_connections""") rows = cur.fetchall _________________") print(row) cur.execute("""show listen_addresses;""") rows = cur.fetchall _____________") print(row) cur.execute("""show maintenance_work_mem;""") rows = cur.fetchall = 'idle' order by 1 desc;""") rows = cur.fetchall() for row in rows: print("PG 服务器当前运行

    1.1K20发布于 2021-11-10
  • 来自专栏python3

    python操作sqlite3小结

    .fetchall()用来从结果中取出所以记录 .scroll()用于游标滚动 2、创建表 首先使用游标创建一个person表,包含id,name,age等3列,代码如下: cur.execute ()和fetchone()方法 fetchall()方法获取所有数据,返回一个二维列表。 fetchone()方法获取其中一个结果,返回一个元组 res = cur.fetchall() for line in res: print("循环fetchall的值>>>",line) 要从新取才能再次取数据哦 () for line in res: print("循环删除之后的数据>>>",line) 最后 con.close() # 关闭数据库链接 输出结果: 循环fetchall的值 >>> (1, ‘leon’, 22) 循环fetchall的值>>> (2, ‘name2’, 28) 循环fetchall的值>>> (3, ‘name3’, 19)

    1.2K10发布于 2020-01-03
  • 来自专栏生活处处有BUG

    Python入门系列(十一)一篇搞定python操作MySQL数据库

    () for x in myresult: print(x) 注意:我们使用fetchall()方法,它从最后执行的语句中获取所有行。 "SELECT * FROM customers WHERE address ='Park Lane 38'" mycursor.execute(sql) myresult = mycursor.fetchall = "SELECT * FROM customers WHERE address LIKE '%way%'" mycursor.execute(sql) myresult = mycursor.fetchall mycursor = mydb.cursor() mycursor.execute("SELECT * FROM customers LIMIT 5") myresult = mycursor.fetchall = mydb.cursor() mycursor.execute("SELECT * FROM customers LIMIT 5 OFFSET 2") myresult = mycursor.fetchall

    66440编辑于 2022-09-05
  • 来自专栏NLP/KG

    MySQL【五】与python交互

    需要执行的语句(增删改查):这里视具体情况而定     五、释放游标:CLOSE 游标名称; 首先fetchone()函数它的返回值是单个的元组,也就是一行记录,如果没有结果,那就会返回null 其次是fetchall ()函数,它的返回值是多个元组,即返回多个行记录,如果没有结果,返回的是() fetchall(参数),写几条返回几条 #举个例子:cursor是我们连接数据库的实例 fetchone()的使用: input) result=cursor.fetchone(); 此时我们可以通过result[0],result[1],result[2]得到username,password,nickname fetchall ()的使用: cursor.execute(select * from user) result=cursor.fetchall();此时select得到的可能是多行记录,那么我们通过fetchall for i in range(count): #获取查询的结果 result = cs1.fetchone() #返回一个元组一条一条取 fetchmany()和fetchall

    82310编辑于 2022-12-21
  • 来自专栏python3

    python 统计MySQL表信息

    int类型 ) cur = conn.cursor()  # 创建游标 # 获取mysql中所有数据库 cur.execute('SHOW DATABASES') data_all = cur.fetchall int类型 ) cur = conn.cursor()  # 创建游标 # 获取mysql中所有数据库 cur.execute('SHOW DATABASES') data_all = cur.fetchall int类型 ) cur = conn.cursor()  # 创建游标 # 获取mysql中所有数据库 cur.execute('SHOW DATABASES') data_all = cur.fetchall int类型 ) cur = conn.cursor()  # 创建游标 # 获取mysql中所有数据库 cur.execute('SHOW DATABASES') data_all = cur.fetchall int类型 ) cur = conn.cursor()  # 创建游标 # 获取mysql中所有数据库 cur.execute('SHOW DATABASES') data_all = cur.fetchall

    5.8K30发布于 2020-01-20
  • 来自专栏玖叁叁

    python-Python与PostgreSQL数据库-处理PostgreSQL查询结果

    获取查询结果在Python中,我们可以使用psycopg2库的fetchone()方法和fetchall()方法获取查询结果。 fetchone()方法用于获取查询结果的一行,而fetchall()方法用于获取所有行的结果。 for row in rows: print(row)# 关闭游标和连接cursor.close()conn.close()在上面的示例代码中,我们使用psycopg2库的fetchone()方法和fetchall )# 创建一个游标对象cursor = conn.cursor()# 执行查询cursor.execute("SELECT * FROM mytable")# 处理查询结果rows = cursor.fetchall )# 创建一个游标对象cursor = conn.cursor()# 执行查询cursor.execute("SELECT * FROM mytable")# 处理查询结果rows = cursor.fetchall

    2.6K11编辑于 2023-04-22
  • 来自专栏技术派

    php mysql PDO 查询操作的实例详解

    PDOStatement::fetchAll()是获取所有记录集到一个中。 注解: 1、选fetch还是fetchall? 小记录集时,用fetchall效率高,减少从数据库检索次数,但对于大结果集,用fetchall则给系统带来很大负担。 cursor_offset]]]) array pdostatement::fetchAll(int fetch_style) fetch_style参数: ■$row=$rs->fetchAll(PDO ■$row=$rs->fetchAll(PDO::FETCH_ASSOC); FETCH_ASSOC参数决定返回的只有关联数组。 ■$row=$rs->fetchAll(PDO::FETCH_NUM); 返回索引数组 ■$row=$rs->fetchAll(PDO::FETCH_OBJ); 如果fetch()则返回对象,如果是fetchall

    3.3K20发布于 2021-07-08
  • 来自专栏玩转编程

    Python 系列文章 —— sqlite 详解

    cs.close() conn.commit() conn.close() 查询 cs.execute("SELECT id, name FROM student") data = cs.fetchall ) conn.close() 修改 cs.execute("SELECT id, name FROM student WHERE id = '1'") print('修改前-->', cs.fetchall Nicolas' WHERE id = '1'") cs.execute("SELECT id, name FROM student WHERE id = '1'") print('修改后-->', cs.fetchall conn.commit() cs.close() conn.close() 删除 cs.execute("SELECT id, name FROM student") print('删除前-->', cs.fetchall DELETE FROM student WHERE id = '1'") cs.execute("SELECT id, name FROM student") print('删除后-->', cs.fetchall

    41500编辑于 2022-01-15
  • 来自专栏Python编程 pyqt matplotlib

    python 标准库 sqlite3 介绍(二)

    (): print(row) c.execute("SELECT * FROM department") print("部门信息:") for row in c.fetchall(): dept FROM employee CROSS JOIN department") print("CROSS JOIN") print("雇员ID, 姓名,部门:") for row in c.fetchall USING)") print("雇员ID, 姓名,年龄,城市,薪资,部门,部门ID:") for row in c.fetchall(): print(row) print() '''自然连接( USING)") print("雇员ID, 姓名,年龄,城市,薪资,部门,部门ID:") for row in c.fetchall(): print(row) print() ? , (22000, 22000)) conn.commit() print("低的调高") c.execute("select * from employee") for row in c.fetchall

    1.4K30发布于 2019-08-14
  • 来自专栏DrugOne

    RDKit支持PostgreSQL配置

    ='aspirin12369', port="5432") cursor = c.cursor() cursor.execute("select version()") reply = cursor.fetchall mw float, logp float ); """) cursor.execute("select * from drugbank.drugbank") print(cursor.fetchall (query) print(query[:1000]) cursor.execute("select count(*) from drugbank.drugbank") print(cursor.fetchall (), len(drugbank)) cursor.execute("select * from drugbank.drugbank limit 10") print(cursor.fetchall cursor.execute("select * from drugbank.drugbank where id > 500 and id < 600 limit 10;") print(cursor.fetchall

    1.4K10发布于 2021-01-28
  • 来自专栏云计算与大数据技术

    python3连接postgresql工具类

    __cursor.fetchall(): dbs.append(db[0]) return dbs def list_user_tables(self, __cursor.fetchall() def execute(self, sql, vars=None): """获取SQL执行结果""" self. __cursor.fetchall() def get_version(self, vars=None): """获取MySQL版本""" self. __cursor.fetchall() def get_table_fields(self, table, vars=None): """获取表字段信息""" __cursor.fetchall(): fields.append(field) return fields if __name__ == "__main__

    2.3K30编辑于 2022-01-05
  • 来自专栏授客的专栏

    Python clickhouse-driver 类库使用学习总结

    clickhouse_driver.connect(connection_str) cursor = conn.cursor() cursor.execute('SHOW TABLES') res = cursor.fetchall ('table1',), ('test',)] # 删除表 cursor.execute('DROP TABLE IF EXISTS test') print(cursor.fetchall ()) # 输出:[] cursor.execute('CREATE TABLE test (x Int32) ENGINE = Memory') print(cursor.fetchall cursor.rowcount) # 输出:5 print(cursor.columns_with_types) # 输出:[('x', 'Int32')] res = cursor.fetchall cursor.execute('SELECT * FROM test') print(cursor.fetchone()) # 输出:(100,) print(cursor.fetchall

    57600编辑于 2024-11-21
  • 来自专栏硬核项目经理的专栏

    PHP中的PDO操作学习(四)查询结构集

    fetchAll() 方法 通过 fetch() 方法,我们可以获得结果集中的全部数据,不过还是需要一个循环才能进行遍历,多少还是有点麻烦。 其实,PDO 早就为我们准备好了另一个方法,fetchAll() 就是返回一个包含结果集中所有行的数组。 所以我们如果在不重新 execute() 情况下再次调用 fetchAll() 的话,获取的就是空的数据。因为游标已经到底了。 (PDO::FETCH_CLASS, 'User', ['FetchAll User']); print_r($list); // FetchAll User // FetchAll User // Array 在这段代码中,结果集并不会通过 fetchAll() 方法的返回值赋值给 $list 变量了。因为数据都已经传递给了指定的 getValue() 方法了。

    1.6K20发布于 2020-12-30
  • 来自专栏python3

    python MySQLdb 模块

    那就用fetchall()方法 #! 方法获取全部结果 print cur.fetchall() print 'select %s lins'%reCount 这次的执行结果如下 ((1L, 1L, 'wgw', '123456', 0L) 方法获取全部结果 print cur.fetchall() print 'select %s lines'%reCount 运行结果如下 {'tid': 1L, 'passwd': '123456',  别切片方式省事多了 再看看fetchall的效果 #! 方法获取全部结果 print cur.fetchall() print 'select %s lines'%reCount 运行结果如下: ({'tid': 1L, 'passwd': '123456'

    1.5K20发布于 2020-01-07
  • 来自专栏全栈程序员必看

    python3基础:操作mysql数据库

    cursor对象还提供了3种提取数据的方法:fetchone、fetchmany、fetchall.。每个方法都会导致游标动,所以必须注意游标的位置。 cursor. fetchall():接收全部的返回结果行。 fetmany()函数必须跟exceute()函数结合使用,并且在exceute()函数之后使用 代码示例:fetchall ‘’‘fetchall’’’ import pymysql #打开数据库连接 cur.execute("select * from user where name in ('kongsh','wen');") print('更新前的数据为:') for res in cur.fetchall cur.execute("select * from user where name in ('kongsh','wen');") print('更新后的数据为:') for res in cur.fetchall

    1.3K40编辑于 2022-09-05
  • 来自专栏python3

    第十三章 Python数据库编程

    关闭游标 execute(sql) 执行sql语句 excutemany(sql) 执行多条sql语句 fetchone() 从执行结果中取第一条记录 fetchmany(n) 从执行结果中取n条记录 fetchall (sql) 1L >>> conn.commit()  # 提交事务,写入到数据库 >>> cursor.execute('show tables')  # 查看创建的表 1L >>> cursor.fetchall 返回上一个游标执行的所有结果,默认是以元组形式返回 ((u'user',),) >>> cursor.execute('select * from user')            1L >>> cursor.fetchall sql, args) 3L >>> conn.commit() >>> sql = 'select * from user' >>> cursor.execute(sql) 4L >>> cursor.fetchall     cursor = conn.cursor()     sql = "select * from user"     cursor.execute(sql)     for i in cursor.fetchall

    49120发布于 2020-01-06
  • 来自专栏程序人生丶

    Python MySQL 数据库查询:选择数据、使用筛选条件、防止 SQL 注入

    mydatabase" ) mycursor = mydb.cursor() mycursor.execute("SELECT * FROM customers") myresult = mycursor.fetchall () for x in myresult: print(x) 注意:我们使用 fetchall() 方法,该方法从上次执行的语句中获取所有行。 mycursor = mydb.cursor() mycursor.execute("SELECT name, address FROM customers") myresult = mycursor.fetchall "SELECT * FROM customers WHERE address ='Park Lane 38'" mycursor.execute(sql) myresult = mycursor.fetchall = "SELECT * FROM customers WHERE address LIKE '%way%'" mycursor.execute(sql) myresult = mycursor.fetchall

    1.2K20编辑于 2023-11-10
领券