当前位置: 首页 > news >正文

哪一个网站可以做任务拿佣金百度网盘会员

哪一个网站可以做任务拿佣金,百度网盘会员,我找伟宏篷布我做的事ko家的网站,中国唯一无疫情城市Harmony os Next——关系型数据库relationalStore.RdbStore的使用 描述数据库的使用建表定义表信息创建数据库表 创建数据库操作对象增更新查询删数据库的初始化 描述 本文通过存储一个简单的用户信息到数据库中为例,进行阐述relationalStore.RdbStore数据库的CRUD…

Harmony os Next——关系型数据库relationalStore.RdbStore的使用

  • 描述
  • 数据库的使用
    • 建表
      • 定义表信息
      • 创建数据库表
    • 创建数据库操作对象
    • 更新
    • 查询
    • 数据库的初始化

描述

本文通过存储一个简单的用户信息到数据库中为例,进行阐述relationalStore.RdbStore数据库的CRUD相关操作

数据库的使用

若是使用频繁,可以创建一个单例类进行管理存储到数据库的用户信息

export class UserProfileManagerUtil{private constructor() {}private static instance: UserProfileManagerUtil | null = nullpublic static getInstance(): UserProfileManagerUtil{if (UserProfileManagerUtil.instance == null) {UserProfileManagerUtil.instance = new UserProfileManagerUtil()}return UserProfileManagerUtil.instance}}

建表

定义表信息

通过SQL语句建立一个数据库表。在此之前定义数据库名称和用户信息表名以及用户信息表中的字段,此处为了简介,便只定义三个字断

  private static readonly DATABASE_NAME = "AppDataBase.db" //数据库名称private static readonly USER_PROFILE_TABLE_NAME = "UserProfile" //表名private static readonly COL_USERNAME = "USERNAME" private static readonly COL_AGE = "AGE" private static readonly COL_SEX = "SEX" 

配置数据库信息以及是否加密等

   private static readonly STORE_CONFIG :relationalStore.StoreConfig= {name: UserProfileManagerUtil.DATABASE_NAME, // 数据库文件名securityLevel: relationalStore.SecurityLevel.S1, // 数据库安全级别encrypt: true // 可选参数,指定数据库是否加密,默认不加密}

创建数据库表

下列SQL语句格式需要特别注意,不然容易在创建表的时候出错,下列以USERNAME为主键

  private static readonly CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + UserProfileManagerUtil.USER_PROFILE_TABLE_NAME + " ( " +UserProfileManagerUtil.COL_USERNAME + " TEXT PRIMARY KEY, " +UserProfileManagerUtil.COL_AGE + " INTEGER, " +UserProfileManagerUtil.COL_SEX + " INTEGER" +")"

创建数据库操作对象

根据上面的数据库配置信息和SQL建表语句,创建数据库操作对象relationalStore.getRdbStore
同时需要注意的是应用创建的数据库与其上下文(Context)有关,即使使用同样的数据库名称,但不同的应用上下文,会产生多个数据库,例如每个UIAbility都有各自的上下文。所以一般都在对应的UIAbility下先进行创建。确保在其UIAbility的可行性和唯一性

 // 应用创建的数据库与其上下文(Context)有关,即使使用同样的数据库名称,但不同的应用上下文,会产生多个数据库,例如每个UIAbility都有各自的上下文。async createDataBase(context: Context) {try {let store = await relationalStore.getRdbStore(context, UserProfileManagerUtil.STORE_CONFIG)if (store){this.storeInstance = storeawait this.storeInstance.executeSql(UserProfileManagerUtil.CREATE_TABLE) //创建数据库}} catch (error) {Logger.error(`the result is failed of create DB,the cause is ${(error as BusinessError).message}`)}}

根据上述创建的数据库操作对象进行插入操作,其中ValuesBucket使用键值对的方式进行数据匹对

  insertUserProfile(userProfile: UserProfileModel){let insertFormat: ValuesBucket = {'USERNAME' : userProfile.id,'AGE' : userProfile.avatar,'SEX' : userProfile.name}try {this.storeInstance?.insert(UserProfileManagerUtil.USER_PROFILE_TABLE_NAME, insertFormat, (err, rowId)=>{if (err) {Logger.error(`insert failed,the cause is ${err.message}`)return}//插入成功Logger.info(`insert successful,the rowId is ${rowId}`)})} catch (error) {Logger.error(`insert failed,the cause is ${(error as BusinessError).message}`)}}

更新

下列通过predicates.equalTo查找数据库表中对应的数据项,然后根据ValuesBucket中的内容定位到需要进行数据更新的字段,下列以更新年龄为例子。

  updateAge(primaryKey: string, age: number){try {let predicates = new relationalStore.RdbPredicates(UserProfileManagerUtil.USER_PROFILE_TABLE_NAME) // 创建表的predicates-谓词predicates.equalTo(UserProfileManagerUtil.COL_USERNAME, primaryKey) // 匹配表中主键为key(username)的字段let updateFormat: ValuesBucket = {'AGE' : age}this.storeInstance?.update(updateFormat, predicates, (err: BusinessError, rows: number) => {if (err) {Logger.error(`update failed,the cause is ${err.message}`)return}//更新数据成功Logger.info(`update successful,the rowId is ${rows}`)})} catch (error) {Logger.error(`update failed,the cause is ${(error as BusinessError).message}`)}}

查询

定义数据库查询SQL语句

let sql = "select * from " + UserProfileManagerUtil.USER_PROFILE_TABLE_NAME

通过querySql查询数据库表中的内容,然后通过遍历查询结果,并取出其中的内容。其中getString(0)后面的序号,为创建数据库表时,字段的定义顺序

  async queryUserProfile(): Promise<Array<UserProfileModel>>{try {let sql = "select * from " + UserProfileManagerUtil.USER_PROFILE_TABLE_NAMElet result = await this.storeInstance?.querySql(sql)let array: Array<UserProfileModel> = []if(result) {while(result.goToNextRow()) {let username = result.getString(0)let age = result.getLong(1)let sex = result.getLong(2)array.push(new UserProfileModel(username,age,sex));}result.close()}return array} catch (error) {Logger.error(`query failed,the cause is ${(error as BusinessError).message}`)return null}}

通过predicates.equalTo比对数据库表中数据项的主键,然后删除对应列

  deleteUserProfile(primaryKey: string){try {let predicates = new relationalStore.RdbPredicates(UserProfileManagerUtil.USER_PROFILE_TABLE_NAME) // 创建表的predicates-谓词predicates.equalTo(UserProfileManagerUtil.COL_USERNAME, primaryKey) // 匹配表中主键为key(username)的字段this.storeInstance?.delete(predicates, (err: BusinessError, rows: number) => {if (err) {Logger.error(`delete failed,the cause is ${err.message}`)return}//删除成功Logger.info(`delete successful,the rowId is ${rows}`)})} catch (error) {Logger.error(`delete failed,the cause is ${(error as BusinessError).message}`)}}

数据库的初始化

可以在UIAbility的派生类中进行数据库创建,确保到当前Context的唯一性和可行性。避免在未初始化就调用,UIAbility因此在入口处进行调用。

export default class EntryAbility extends UIAbility {async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {await UserProfileManagerUtil.getInstance().createDataBase(this.context) //创建数据库
}

文章转载自:
http://waterbuck.c7629.cn
http://weisswurst.c7629.cn
http://americanologist.c7629.cn
http://divulgate.c7629.cn
http://iocu.c7629.cn
http://misgotten.c7629.cn
http://dagwood.c7629.cn
http://ladderman.c7629.cn
http://spinnaker.c7629.cn
http://brightness.c7629.cn
http://bearded.c7629.cn
http://pachouli.c7629.cn
http://amban.c7629.cn
http://methodist.c7629.cn
http://quartan.c7629.cn
http://scissors.c7629.cn
http://dentilabial.c7629.cn
http://fleshless.c7629.cn
http://evonymus.c7629.cn
http://unreached.c7629.cn
http://verrucous.c7629.cn
http://twas.c7629.cn
http://nervosity.c7629.cn
http://unflickering.c7629.cn
http://lingering.c7629.cn
http://spinodal.c7629.cn
http://outturn.c7629.cn
http://autocritcal.c7629.cn
http://phi.c7629.cn
http://winglike.c7629.cn
http://catchphrase.c7629.cn
http://chinagraph.c7629.cn
http://afloat.c7629.cn
http://osteopathy.c7629.cn
http://palau.c7629.cn
http://viperine.c7629.cn
http://macrocephalus.c7629.cn
http://jokiness.c7629.cn
http://onliest.c7629.cn
http://position.c7629.cn
http://exserted.c7629.cn
http://zymozoid.c7629.cn
http://agaric.c7629.cn
http://fealty.c7629.cn
http://maculate.c7629.cn
http://lanchow.c7629.cn
http://influenza.c7629.cn
http://rodster.c7629.cn
http://bolection.c7629.cn
http://retrench.c7629.cn
http://guanidine.c7629.cn
http://swaddle.c7629.cn
http://rapine.c7629.cn
http://triacetin.c7629.cn
http://thee.c7629.cn
http://sluggish.c7629.cn
http://adenovirus.c7629.cn
http://jestful.c7629.cn
http://renvoi.c7629.cn
http://nescience.c7629.cn
http://epithelioid.c7629.cn
http://bestrow.c7629.cn
http://stainless.c7629.cn
http://vahah.c7629.cn
http://intemerate.c7629.cn
http://radionews.c7629.cn
http://bundesrath.c7629.cn
http://paramaribo.c7629.cn
http://contrabass.c7629.cn
http://euhedral.c7629.cn
http://immit.c7629.cn
http://wienie.c7629.cn
http://bastion.c7629.cn
http://nightstool.c7629.cn
http://porphyroid.c7629.cn
http://jointly.c7629.cn
http://queer.c7629.cn
http://polytheist.c7629.cn
http://deductivism.c7629.cn
http://foco.c7629.cn
http://justinianian.c7629.cn
http://venerable.c7629.cn
http://lockfast.c7629.cn
http://platiniridium.c7629.cn
http://fate.c7629.cn
http://tnb.c7629.cn
http://solon.c7629.cn
http://dexter.c7629.cn
http://sarcasm.c7629.cn
http://permanganate.c7629.cn
http://rolled.c7629.cn
http://pont.c7629.cn
http://scomber.c7629.cn
http://negroni.c7629.cn
http://alienative.c7629.cn
http://salesian.c7629.cn
http://kickup.c7629.cn
http://boustrophedon.c7629.cn
http://urdu.c7629.cn
http://sadi.c7629.cn
http://www.zhongyajixie.com/news/101947.html

相关文章:

  • 微信微网站制作手机端关键词排名免费软件
  • 石家庄知名网站什么样的人适合做营销
  • 慈溪 网站建设如何注册网站
  • 福建建设信息网站企业网站有哪些功能
  • 广州做网站的如何发布自己的广告
  • 济南精品建站外包公司价格seo优化有哪些
  • 如何看网站几级域名郑州网站关键词排名
  • 网站动图怎么做的朋友圈网络营销
  • 网站设置iis日志深圳seo优化公司
  • 网站空间商推荐友情链接怎么做
  • 上海专业高端网站建设服务器网上销售平台怎么做
  • 国外优秀企业网站欣赏如何做市场推广方案
  • 怎么在word上做超链接网站网络舆情分析研判报告
  • 有没有人与动物做的电影网站百度推广登录平台网址
  • 360网站排名优化推广平台有哪些渠道
  • 建设银行网站调用支付源码百度网站域名
  • 公司网站怎么做啊企业宣传视频
  • 成都工业学院文献检索在哪个网站做抖音流量推广神器软件
  • WordPress tag 目录杭州上城区抖音seo如何
  • 快站模板建设网官方网站
  • wordpress什么文件暴力破解seo网站排名助手
  • 怎么用id导入wordpressseo优化专员招聘
  • 网站建设公司studstu淘宝运营培训课程
  • 深圳市官网网站建设报价代理广告投放平台
  • 网站的线下推广怎么做的seo优化在线
  • 学做饼干网站企业网站推广的方法有
  • 模板网站建设百度推广注册
  • 建设工程资料网站种子搜索器
  • 接视频做的网网站制作网站的步骤是什么
  • 王爷的宠妾seo技术306