godot 如何使用 sqlite 数据库?

分类栏目:Godot教程

150

godot如何使用sqlite来管理数据?

很简单,godot本身就有sqlite的插件,在godot  assetlib  里面搜索 sqlite 第一个 就是,点击等待下载

然后说下大概的代码


extends Node2D

var  sqlite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")  //引入gbsqlite 插件
var db
var db_path='res://xx.db'   设置db数据库文件
# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
db=sqlite.new()
db.path='pbootcms.db' 设置db数据库名称
db.open_db()
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass


func _on_Button_pressed():
pass # Replace with function body.

//下面是点击读取代码
func _on_Button2_pressed():
db.query('select *  from company;')
var  rows=db.query_result
print(rows[0]['phone']) //直接读取第一条的电话号码
for row in rows:
print(row['phone']) //循环输出电话号码


pass # Replace with function body.