123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- function openFSqlite(){
-
- return new Promise((resolve,reject) =>{
- plus.sqlite.openDatabase({
- name:'f',
- path:'_doc/f.db',
-
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }
- function createFSQL(userId){
- return new Promise((resolve,reject) =>{
-
- plus.sqlite.executeSql({
- name:'f',
-
- sql:'create table if not exists s_friend_'+userId+' ("id" INT(11) PRIMARY KEY NOT NULL,"nickName" CHAR(255),"name" CHAR(255),"avatar" CHAR(255))',
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }
- function addFSQL(obj,userId){
-
- if(obj !== undefined){
-
- var b = (JSON.stringify(obj) == "{}");
- if(!b){
-
- var id = obj.id || null;
- var nickName = obj.nickName || null;
- var name = obj.name || null;
- var avatar = obj.avatar || null;
- return new Promise((resolve,reject) =>{
- plus.sqlite.executeSql({
- name:'f',
- sql:"INSERT INTO s_friend_" + userId + " (`id`, `nickName`, `name`, `avatar`) VALUES ('" + id + "', '" + nickName + "', '" + name + "', '" + avatar + "')",
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }else{
- return new Promise((resolve,reject) =>{reject("错误添加")})
- }
- }else{
- return new Promise((resolve,reject) =>{reject("错误添加")})
- }
- }
- function selectFSQL(userId){
- if(userId !== undefined){
-
- var sql = 'select * from s_friend_'+userId;
- return new Promise((resolve,reject)=>{
- plus.sqlite.selectSql({
- name:'f',
- sql:sql,
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }else{
- return new Promise((resolve,reject) =>{reject("错误查询")});
- }
- }
- function deleteFSQL(name,sol,qq,ww,ee){
- if(name !== undefined && sol !== undefined){
-
- if(ww !== undefined){
-
- var sql = 'delete from '+name+' where '+sol+'="'+qq+'" and '+ww+'='+ee+'';
- }else{
-
- var sql = 'delete from '+name+' where '+sol+'="'+qq+'"';
- }
- return new Promise((resolve,reject) =>{
- plus.sqlite.executeSql({
- name:'f',
- sql:sql,
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }else{
- return new Promise((resolve,reject) =>{reject("错误删除")});
- }
- }
- function modifyFSQL(listName,name,cont,use,sel){
-
- var sql;
- if(use == undefined){
- sql ='update '+listName+' set '+name+'="'+cont+'"';
- }else{
- sql ='update '+listName+' set '+name+'="'+cont+'" where '+use+'="'+sel+'"';
- }
-
- return new Promise((resolve,reject) =>{
- plus.sqlite.executeSql({
- name:'f',
- sql:sql,
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }
- function closeSQL(name){
- return new Promise((resolve,reject) =>{
- plus.sqlite.closeDatabase({
- name:'f',
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }
- function isOpen(name,path){
- var ss = name || 'f';
- var qq = path || '_doc/f.db';
-
- var open = plus.sqlite.isOpenDatabase({
- name:ss,
- path:qq
- })
- return open;
- }
- function pullSQL(id,num){
-
-
- return new Promise((resolve,reject) =>{
- plus.sqlite.selectSql({
- name:'f',
- sql:'select * from '+id+' order by list desc limit 15 offset '+num+'',
- success(e){
- resolve(e);
- },
- fail(e){
- reject(e);
- }
- })
- })
- }
- export{
- openFSqlite,
- createFSQL,
- addFSQL,
- selectFSQL
- }
|