python小技巧大应用--测试SQLite是否好用

在很多小的应用开发中对数据的管理完全没必要让Mysql之类的大神级数据库登场,直接使用python自带的SQLite就已经足够了.

(我就要小轻快,能快速落地实用,可不想动不动就安装个数据库服务器之类的,忒麻烦.)

1.先测试一下python对SQLite操作是否好用

1)pycharm下建个项目test-SQLite,建个文件test_sqlitedb.py代码如下:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
' a test sqlite '
__author__ = 'TianJiang Gui'

import sqlite3
conn = sqlite3.connect('sqlite-data.db')
cursor = conn.cursor()
cursor.execute('create table userinfo (id int(11) primary key, name varchar(20), age int)')
cursor.execute('insert into userinfo (id, name, age) values (1, \'gtj\', 45)')
print(cursor.rowcount)
cursor.execute('select * from userinfo where id=?', (1,))
values = cursor.fetchall()
print(values)

cursor.close()
conn.close()

过程很轻松,结果很完美:

 但是别高兴的太早了,打开Navicate for SQLite 再看看是否真的有数据:

 怎么会没有数据呢?在此重要的问题说三遍:在执行了增,删,改后一定要记得执行

conn.commit()

2.最终正确的代码在此:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
' a test sqlite '
__author__ = 'TianJiang Gui'

import sqlite3
conn = sqlite3.connect('sqlite-data.db')
cursor = conn.cursor()
cursor.execute('create table userinfo (id int(11) primary key, name varchar(20), age int)')
cursor.execute('insert into userinfo (id, name, age) values (1, \'gtj\', 45)')
print(cursor.rowcount)

# ---gtj 一定记得执行commit
conn.commit()

cursor.execute('select * from userinfo where id=?', (1,))
values = cursor.fetchall()
print(values)

cursor.close()
conn.close()

再次通过Navicate for SQLite查看

 现在才真的有数据了.

总结:python+sqlite真是完美的小应用开发组合,随后我就将对mysql的操作改造为对sqlite的操作,这样也便于我打包生成应用程序

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
SQLite Expert: A powerful administration tool for your SQLite databases Are you developing SQLite3 databases and need an easy and powerful tool? SQLite Expert is the perfect choice. It is the most feature rich administration and development tool for SQLite. SQLite Expert is designed to answer the needs of all users, from writing simple SQL queries to developing complex databases. The graphical interface supports all SQLite features. It includes a visual query builder, an SQL editor with syntax highlighting and code completion, visual table and view designers and powerful import and export capabilities. Supported platforms: Windows 2000, XP, Vista, 7. Visual SQL Query Builder Build complex SQL queries with ease. Formatted SQL query text layout. Powerful means of SQL query parsing and analysis. Advanced SQL editor with syntax highlighting and code completion. Powerful restructure capabilities Visual editors for table columns, indexes, foreign keys, triggers, unique and check constraints. Restructure any complex table without losing data. Any restructure operation is wrapped in a nested transaction which is rolled back if any errors occur when applying changes. Import and Export data Import data from ADO data source, CSV files, SQL script or SQLite. Export data to CSV files, SQL script, Excel or SQLite. Copy tables between SQLite databases using drag and drop operations. Export data to Excel via clipboard. Data editing Edit data in the grid using powerful in-place editors. Image editor currently supporting JPEG, PNG, BMP, GIF and ICO image formats. Visualize and modify BLOB fields using the integrated Hex editor. Other features Full Unicode support. Support for attached databases. Support for encrypted databases. Lua and Pascal scripting support. Recent features View all the functions and collations installed by each SQLite extension! New in 3.0: Customize the look and feel of the application using skins. New in 3.0: Send the contents of any grid to printer or export it to a PDF file. SQLite的专家:一个强大的管理工具,为您的SQLite数据库 你发展sqlite3的数据库,并需要一个简单而强大的的工具? SQLite的专家是最完美的选择。它是功能最丰富的管理和对SQLite开发工具。 SQLite的专家的目的是回答所有用户的需求,编简单的SQL查询,以开发复杂的数据库。 图形界面,支持所有的SQLite功能。它包括一个可视化查询生成器,SQL编辑器与语法高亮和代码完成,视力表和视图设计师和强大的进口和出口能力。 支持平台:视窗2000,XP,VISTA,7。 可视SQL查询生成器 轻松建立复杂的SQL查询。 格式化的SQL查询文本布局。 SQL查询解析和分析的有力手段。 高级SQL编辑器与语法高亮和代码完成。 强大的重组功能 表列,索引,外键,触发器,独特和检查约束的可视化编辑器。 任何复杂的表,而不会丢失数据重组。 任何重组操作被包裹在一个嵌套事务回滚,如果发生任何错误更改应用时。 导入和导出数据 从ADO数据源,CSV文件,SQL脚本SQLite导入数据。 数据导出到CSV文件,SQL脚本,Excel或SQLite的。 使用拖放操作之间的SQLite数据库复制表。 通过剪贴板中的数据导出到Excel。 数据编辑 在使用功能强大的就地编辑网格的编辑数据。 图像编辑器目前支持JPEG,PNG,BMP,GIF和ICO图像格式。 使用集成的十六进制编辑器可视化和修改BLOB字段。 其他特点 完整的Unicode支持。 支持附加的数据库。 支持加密的数据库。 Lua和Pascal的脚本支持。 最新功能 查看所有的功能和安装排序规则每个SQLite扩展! 在3.0的新功能:自定义的外观和感觉的应用程序使用外观。 在3.0的新功能:发送到打印机的网格任何内容或将其导出到一个PDF文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿桂天山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值