Sqlite教程(3) SQlite Query

Configuration是属於util工具包。

把所有环境设置都定义在Configuration工具包里,那麽这个Configuration就是独立的单一入囗。

在架构上,可以提高耦合度,而且出Bug时也方便追纵。

更重要的是,假如表格的Name需要改变,那只要在Configuration里改一下变量就行,不用担心其他控件会因此出Bug。

这里第一部份定义了SQlite的Query,第二部份定义了okhttp的URL。

1. SQlite的Query

/*
    *   SQLite
     */
    public static final String DB_NAME = "epdz.db";
    public static int DB_VERSION = 23;

    /*
    *   SQLite [Table]User
     */
    public static final String DB_USER = "epdz_user";
    public static final String USER_ID = "id";
    public static final String USER_USERID = "userId";
    public static final String USER_NAME = "name";
    public static final String USER_PASSWORD = "password";
    public static final String USER_EMAIL = "email";
    public static final String USER_DESCRIPTION = "description";
    public static final String USER_TEAM = "team";
    public static final String USER_ACADEMIC = "academic";
    public static final String USER_PORTRAIT = "portrait";
    public static final String USER_PORTRAIT_DATA = "portraitData";
    public static final String USER_REGISTER_DATE = "registerDate";

    /*
    * SQLite [Table]Post
     */
    public static final String DB_POST = "epdz_post";
    public static final String POST_ID = "pid";
    public static final String POST_POSTID = "id";
    public static final String POST_CATEGORY = "category";
    public static final String POST_DATE = "date";
    public static final String POST_AUTHORID = "authorId";
    public static final String POST_EDITORID = "editorId";
    public static final String POST_TITLE = "title";
    public static final String POST_ABSTRACT = "abstract";
    public static final String POST_ABSTRACTIMG = "abstractImg";
    public static final String POST_CONTEXT = "context";
    public static final String POST_ISTOP = "isTop";
    public static final String POST_VISITABLE = "visitable";
    public static final String POST_AUTHORNAME = "authorName";
    public static final String POST_EDITORNAME = "editorName";
    public static final String POST_CATEGORYNAME = "categoryName";

    /*
    *   SQlite [Table] Create user
     */
    public static final String CREATE_USER_TABLE = " CREATE TABLE " +DB_USER+ " (" +
            USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            USER_USERID + " VARCHAR(256) NOT NULL, " +
            USER_NAME + " VARCHAR(256) NOT NULL, " +
            USER_PASSWORD + " VARCHAR(256) NOT NULL, " +
            USER_EMAIL + " VARCHAR(256), " +
            USER_DESCRIPTION + " VARCHAR(512), " +
            USER_TEAM + " VARCHAR(256), " +
            USER_ACADEMIC + " VARCHAR(256), " +
            USER_PORTRAIT + " VARCHAR(512), " +
            USER_PORTRAIT_DATA + " BLOB, " +
            USER_REGISTER_DATE + " VARCHAR(256) NOT NULL );";

    /*
    *   SQlite [Table] Create post
    */
    public static final String CREATE_POST_TABLE = " CREATE TABLE " +DB_POST+ " (" +
            POST_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            POST_POSTID + " VARCHAR(32) NOT NULL, " +
            POST_CATEGORY + " VARCHAR(32), " +
            POST_CATEGORYNAME + " VARCHAR(32), " +
            POST_DATE + " VARCHAR(32), " +
            POST_AUTHORID + " VARCHAR(32), " +
            POST_AUTHORNAME + " VARCHAR(32), " +
            POST_EDITORID + " VARCHAR(32), " +
            POST_EDITORNAME + " VARCHAR(32), " +
            POST_TITLE + " VARCHAR(512), " +
            POST_ABSTRACT + " VARCHAR(1024), " +
            POST_ABSTRACTIMG + " VARCHAR(1024), " +
            POST_CONTEXT + " VARCHAR(2048), " +
            POST_ISTOP + " VARCHAR(32), " +
            POST_VISITABLE + " VARCHAR(32) );";

2. okhttp的URL

/*
    *   login query
    *   @param [String] userNmae, [String] userPassword
    *   @return [BOOL]result, [String]userId
    */
    public static String isUserExistURL(String userNmae, String userPassword)
    {
        return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=isUserExist&name="+userNmae+"&password="+userPassword;
    }

    /*
    *   get user query
    *   @param [String]userId
    *   @return [array]user
    */
    public static String getUserURL(String userId) {
        return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=getUserByUserId&id="+userId;
    }

    /*
    *   create user query
    *   @param [String] name, [String] password
    *   @return [BOOL]result
    */
    public static String createUserURL(String name, String password) {
        return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=register&name="+name+"&password="+password;
    }

    /*
    *   update user query
    *   @param [UserDTO]userDTO
    *   @return [BOOL]result, [String]userId
     */
    public static String updateUserURL(UserDTO userDTO) {
        Integer id = userDTO.getId();
        String name = userDTO.getName();
        String password = userDTO.getPassword();
        String description = userDTO.getDescription();
        String team = userDTO.getTeam();
        String academic = userDTO.getAcademic();

        return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=updateUser&id="+id+"&name="+name+
"&password="+password+"&description="+description+"&team="+team+"&academic="+academic; } /* * get all post query * @return [array] post */ public static String getAllPost = "http://e-pdz.com/epdz/router/mobile/postRouter.php?action=getAllPost"; /* * get hot post query * @return [array] post */ public static String getHotPost = "http://e-pdz.com/epdz/router/mobile/postRouter.php?action=getHotPost"; /* * get hot post offset query * @param [String]start, [String]amount * @return [array]post */ public static String getHotPostByCursor(Integer start, Integer amount) { return "http://e-pdz.com/epdz/router/mobile/postRouter.php?action=getHotPostByCursor&start="+start+
"&amount="+amount; } /* * get post query * @param [String] category * @return [array] post */ public static String getPostByCategoryURL(String Category) { return "http://e-pdz.com/epdz/router/mobile/postRouter.php?action=getPostByCategory&category="+Category; } /* * get post query * @param [String] postId * @return [array] post */ public static String getPostByIdURL(String id) { return "http://e-pdz.com/epdz/router/mobile/postRouter.php?action=getPostById&postId="+id; } /* * get post query * @param [String] postId * @return [html] post */ public static String getPostHhtmlByIdURL(String id) { return "http://e-pdz.com/epdz/viewAndroid/post/post.php?id="+id; } /* * get user like post * @param [String]userId * @return [array]post */ public static String getLikePostByUserId(String id) { return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=getLikePostByUserId&userId="+id; } /* * get user comment query * @param [String]userId * @return [array]post */ public static String getCommentByWriterId(String id) { return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=getCommentByWriterId&userId="+id; } /* * get user message query * @param [String]receiverId * @return [array]Message */ public static String getMessageByReceiverId(String receiverId) { return "http://e-pdz.com/epdz/router/mobile/userRouter.php?action=getMessageByReceiverId&receiverId="+receiverId; } /* * update portrait query * */ public static String updatePortrait = "http://e-pdz.com/epdz/router/mobile/userRouter.php";

这里只出一部份代码供叁考。

    原文作者:sqlite
    原文地址: https://www.cnblogs.com/chenkuang/p/8120622.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞