Realization of sqlite3 database storage and management based on Dragonboard 410c

Today I will show you how to use the sqlite3 database to store and manage data for the dragonboard 410c development. sqlite3 is a very mini database performance that is widely used in various embedded platforms, including the current Android system using sqlite3. Data storage and management, this article will show how to use Python scripts to access the sqlite3 database system to build and maintain your own data.

First we can call import sqlite3 to import the sqlite3 database python module, and then you can write code to access the sqlite3 database, the specific steps are as follows:

1) Connect to the database

self.DB=sqlite3.connect("database.db")

Through the above code can be connected to the sqlite3 database, and return a maintenance variable for accessing the sqlite3 database, if the database, db does not exist, it will automatically create a database.

2) Get the cursor

Self.cu=self.DB.cursor()

By obtaining the cursor through the above code, you can use this variable to access the database and perform related operations.

3) Execute the SQL statement

self.DB.execute(SQL)

The SQL statement can be executed by the above code.

Understand the above operation interface, we can easily realize the creation of data tables, data reading, inserting and updating, etc. The following is introduced through the design of a specific user message management database, which is used for our subsequent design. Data management of smart mirror, how do you build your own database code on 410c, as follows:

Establish data sheet

Def initTable(self):
Try:
#create userInfo table
self.DB.execute("create table userInfo(userID integer primary key autoincrement,\
Name nvarchar(50),\
Password nvarchar(20),\
Email nvarchar(50),\
Phone nvarchar(50),\
haarValue nvarchar(50),\
avatarImg nvarchar(50))"
)
#create pushInfo table
#********************pushInfo table**********************#
# infoType 0 text info, 1 video info
#
self.DB.execute("create table pushInfo(infoID integer primary key autoincrement,\
ownerID integer,\
pushID integer,\
infoType integer,\
infoSubject nvarchar(50),\
infoContent nvarchar(100),\
filePath nvarchar(1000),\
pushTIme float,\
infoValidityTIme float,\
isTop integer,\
viewWeight integer\
)")
Except:
Print("table is already create")

Similarly we can read the data in the table:

Def getUserAvatarImg(self,userID):
Format="select avatarImg from userInfo where userID==%u"
Values=(userID)
querySQL=format % values
Print(querySQL)
Self.cu.execute(querySQL)
Result=self.cu.fetchone()
If result==None:
Return -1
Else:
Return result[0]

You can also insert data into the table.

Def insertTestData(self,userInfo_n,pushInfo_n):
For userID in range(1,userInfo_n):
Format="test%u"
Values=(userID)
userName=format % values
Format="password_test%u"
Password=format % values
Format="email_test%uqq.com"
userEmail=format % values
Format="phone_test%u"
userPhone=format % values
Format="haarValue_test%u"
haarValues=format % values
Avatar=(random.randint(1,8))
Format="./avatarImg/headImg/ali1/%u.gif"
avatarImg=format % avatar
Format="insert into userInfo values(%u,'%s','%s','%s','%s','%s','%s')"
Values=(userID,userName,password,userEmail,userPhone,haarValues,avatarImg)
insertSQL=format % values
#print(insertSQL)
Self.cu.execute(insertSQL)
For infoID in range(1,pushInfo_n):
ownerID=random.randint(1,userInfo_n)
pushID=random.randint(1,userInfo_n)
infoType=random.randint(0,1)
isTop=random.randint(0,1)
viewWeight=random.randint(1,8)
Format = "infoSubject_pID:%u_wID:%u"
Values=(pushID,ownerID)
infoSubject=format % values
Format = "infoContent_pID:%u_wID:%u"
Values=(pushID,ownerID)
infoContent=format % values
filePath=""
If infoType==1:
Format="./messageFile/ownerID%u/pushID%u_%u.mp4"
Values=(ownerID, pushID, infoID)
filePath=format % values
Else:
filePath="None"
pushTIme=TIme.time()
Format="insert into pushInfo values(%u,%u,%u,%u,'%s','%s','%s',%f,1.0,%u,%u)"
Values=(infoID, ownerID, pushID, infoType, infoSubject, infoContent, filePath, pushTime, isTop, viewWeight)
insertSQL=format % values
#print(insertSQL)
self.DB.execute(insertSQL)

You can also perform an update operation as follows:

Def setViewWeight(self,infoID,weight):
Format="update pushInfo set viewWeight=%u where infoID == %u"
Values=(weight, infoID)
updateSQL=format % values
Self.cu.execute(updateSQL)

Static Frequency Connerter With Threephase Output

Variable Frequency Inverter,Variable Frequency Converter,3 Phase Frequency Converter,Frequency Converter 60Hz To 50Hz 3 Phase

Jinan Xinyuhua Energy Technology Co.,Ltd , https://www.xyhenergy.com