LitePal

匿名 (未验证) 提交于 2019-12-03 00:36:02

郭霖开源项目使用笔记,地址

litepal.xml

<?xml version="1.0" encoding="utf-8"?> <litepal>     <!--         Define the database name of your application.         By default each database name should be end with .db.         If you didn't name your database end with .db, LitePal would plus the suffix automatically for you.         For example:             <dbname value="demo" ></dbname>     -->     <dbname value="basicConfiguration " />     <!--         Define the version of your database.         Each time you want to upgrade your database, the version tag would helps.         Modify the models you defined in the mapping tag, and just make the version value plus one, the upgrade of database will be processed automatically without concern.         For example:             <version value="1" ></version>     -->     <version value="1" />     <!--         Define your models in the list with mapping tag, LitePal will create tables for each mapping class.         The supported fields defined in models will be mapped into columns.         For example:             <list>             <mapping class="com.test.model.Reader"></mapping>             <mapping class="com.test.model.Magazine"></mapping>         </list>     -->     <list>         <mapping class="bean.sync.Block" />         <mapping class="bean.sync.Ground" />         <mapping class="bean.sync.ComplexType" />         <mapping class="bean.sync.IntegratedMachineSieveCloth" />         <mapping class="bean.sync.DrillingFluidMaterial" />     </list>     <!--         Define the cases of the tables and columns name.         Java is a case sensitive language, while database is case insensitive.         LitePal will turn all classes names and fields names into lowercase by default while creating or upgrading database.         Developers can change this behavior into the styles their like.         "keep" will keep the cases of classes and fields.         "upper" will turn all classes names and fields names into uppercase.         "lower" will act as default.         Do not change the value after you run your app for the first time, or it might cause the exception that column can not be found.         value options: keep lower upper         For example:             <cases value="lower" ></cases>     -->     <!--         Define where the .db file should be.         "internal" means the .db file will be stored in the database folder of internal storage which no one can access.         "external" means the .db file will be stored in the path to the directory on the primary external storage device where the application can place persistent files it owns which everyone can access.         "internal" will act as default.         For example:         <storage value="internal"></storage>     --> </litepal>
数据库名不可大写字母开头
<storage value="internal"></storage>时数据库建于data->data->包名->databases <storage value="external"></storage>时数据库建位存但未找到

litepal.xml放于assets下一级包

二或其它级包报错

org.litepal.exceptions.InvalidAttributesException: dbname is empty or not defined in litepal.xml file, or your litepal.xml file is missing.

һ

public class MyOwnApplication extends Application {      @Override     public void onCreate() {         super.onCreate();         LitePal.initialize(this);     }     ... }

public class App extends LitePalApplication {      @Override     public void onCreate() {                super.onCreate();         ...     }     ... }

创建

SQLiteDatabase db = Connector.getDatabase(); 或 Connector.getDatabase();


删除

LitePal.deleteDatabase("数据库名");

数据库头次创后改名即创(即同存多数据库),<version value="1" />设版本不可控。

文章来源: LitePal
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!