sqlite 数据库 查询时显示表字段

bash-2.05b# ls
cert     devm     radius   rule     sqlite3  uibase   vpn
<SPAN style="COLOR: #ff6600">bash-2.05b# ./sqlite3 rule </SPAN>

//启动 进入数据库
SQLite version 3.5.4
Enter ".help" for instructions
<SPAN style="COLOR: #ff6600">sqlite> .tab</SPAN>

  // 显示数据库中表
DomainName             RuleIpFilterStatout    RuleSnatIp          
IpObj                  RuleIpFilterTime       RuleSnatPro 
<SPAN style="COLOR: #ff6600">sqlite> select * from IpObj;  //查询表
</SPAN>

1|test1|0|1|1.0.0.0||
2|test2|8|1|1.0.0.0||
<SPAN style="COLOR: #ff6600">sqlite> .h on</SPAN>

     // 显示表字段命令
<SPAN style="COLOR: #ff6600">sqlite> select * from IpObj;</SPAN>


<SPAN style="COLOR: #ff0000">Id|Name|VsysId|Refcount|StartIp|EndIp|Mask</SPAN>

   // 表字段
1|test1|0|1|1.0.0.0||
2|test2|8|1|1.0.0.0||
<SPAN style="COLOR: #ff6600">sqlite> insert into IpObj (Name,VsysId,Refcount,StartIp,EndIp,Mask) values('a','3','2','1.1.1.1','','');   </SPAN>

 //添加操作 
sqlite> select * from IpObj;
Id|Name|VsysId|Refcount|StartIp|EndIp|Mask
1|test1|0|1|1.0.0.0||
2|test2|8|1|1.0.0.0||
3|a|3|2|1.1.1.1||
<SPAN style="COLOR: #ff6600">sqlite> update IpObj set Name='aaa' where Id=3;</SPAN>

//修改操作
sqlite> select * from IpObj;
Id|Name|VsysId|Refcount|StartIp|EndIp|Mask
1|test1|0|1|1.0.0.0||
2|test2|8|1|1.0.0.0||
3|aaa|3|2|1.1.1.1||
<SPAN style="COLOR: #ff6600">sqlite> delete from IpObj where Id=3;</SPAN>

 // 删除操作
sqlite> select * from IpObj;
Id|Name|VsysId|Refcount|StartIp|EndIp|Mask
1|test1|0|1|1.0.0.0||
2|test2|8|1|1.0.0.0||

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过Python的SQLite模块读取SQLite数据库表里面的text文本字段,然后将其输出到网页上。以下是一个简单的示例代码: ```python import sqlite3 from flask import Flask, render_template app = Flask(__name__) @app.route('/') def index(): # 连接到SQLite数据库并获取游标 conn = sqlite3.connect('example.db') cur = conn.cursor() # 查询数据库表中的text字段 cur.execute("SELECT text_field FROM table_name") results = cur.fetchall() # 将查询结果渲染到模板中 return render_template('index.html', results=results) if __name__ == '__main__': app.run() ``` 在上面的代码中,我们使用Flask框架来创建一个Web应用程序,并使用SQLite模块连接到SQLite数据库。我们定义了一个路由`'/'`,当用户访问网站,会执行`index()`函数。 在`index()`函数中,我们执行了一个SQL查询,将查询结果存储在`results`变量中。然后我们将`results`变量作为参数传递给`render_template()`函数,该函数将渲染模板`index.html`并将`results`变量传递给模板。 接下来,我们需要创建一个模板`index.html`,用于显示查询结果。以下是一个简单的示例模板代码: ```html <!DOCTYPE html> <html> <head> <title>SQLite Text Field</title> </head> <body> <h1>SQLite Text Field</h1> <ul> {% for result in results %} <li>{{ result[0] }}</li> {% endfor %} </ul> </body> </html> ``` 在上面的模板代码中,我们使用`{% for %}`循环遍历`results`变量中的查询结果,并将每个结果输出为一个列表项。注意,我们使用`result[0]`来访问查询结果中的第一个字段。 最后,我们需要确保SQLite数据库中包含一个名为`table_name`的表,并且该表包含一个名为`text_field`的text字段。你可以根据你的需要修改这些名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值