Android xutils Frame (i) dbutils

Source: Internet
Author: User


Frame Address: Https://github.com/wyouflf/xUtils


The permissions Required

< uses-permission android:name="Android.permission.INTERNET"/>

<uses-permissionandroid:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/>


Create a database

Daoconfig config = new daoconfig (context);

Config.setdbname ("Xutils-demo"); DB name

Config.setdbversion (1); DB version

Dbutils db = dbutils.create (config),//db there are other construction methods, such as the listener that contains the version of the Update table.


Create a table

Db.createtableifnotexist (User. Class); Create a table user

Db.save (user);//Save a User object in the table. The user table is also created when the Save action is initially executed


Delete a table

Db.droptable (User.class);


Open transaction

Db.configallowtransaction (true);


DB related Annotati On

  @Check     Check constraint
  @ column   column name
  @ Finder   One-to-many, many-to-many relationships (see use in parent, child of sample)
  @ Foreign   FOREIGN key
  @ Id       PRIMARY key, when int type, default self-increment. Non-self-increment, you need to set the value of the ID
  @ noautoincrement   not self-increment
  @ notnull   not empty
  @ table     name
  @ Transient   Do not write database table structure
  @ unique   UNIQUE constraint


Some common methods

Dbutils db = Dbutils.create (this); User user = new user (); It is important to note that the user object must have an id attribute, or a property User.setemail ("[email protected]") with the @id annotation, user.setname ("Wyouflf");d B.save ( user); When you save an entity with Savebindingid, you assign a value to the ID of the entity ...//find the Parent entity = Db.findbyid (Parent.class, Parent.getid ()); list<parent> list = Db.findall (Parent.class);//Find parent parent = Db.findfirst by Type (Selector.from (Parent.class). Where ("name", "=", "Test")),//is nullparent Parent = Db.findfirst (Selector.from (Parent.class). WHERE ("name", "=", null) );//is not nullparent Parent = Db.findfirst (Selector.from (Parent.class). WHERE ("name", "! =", null));//Where id<54 and (age>20 OR age<30)                                   ORDER by ID LIMIT pageSize OFFSET pageoffsetlist<parent> list = Db.findall (Selector.from (Parent.class) . WHERE ("id", "<", si). and (Wherebuilder.b ("Age", ">",). or ( "Age", "<", ()). ("id").Limit (pageSize). Offset (pageSize * pageIndex));//OP is "in", the last parameter must be an array or an implementation class of iterable (for example, Li St, etc.) Parent test = Db.findfirst (Selector.from (Parent.class). WHERE ("id", "in", New Int[]{1, 2, 3});//OP is "between", The last parameter must be an array or Iterable implementation class (such as list, etc.), Parent test = Db.findfirst (Selector.from (Parent.class). WHERE ("id", "between", new string[]{"1", "5"}));D Bmodel Dbmodel = Db.finddbmodelall (Selector.from (Parent.class). Select ("name"));//select (" Name ") only remove the name column list<dbmodel> dbmodels = Db.finddbmodelall (Selector.from (Parent.class). GroupBy (" name "). Select ("Name", "Count (name)"); ... list<dbmodel> dbmodels = db.finddbmodelall (sql); Custom SQL query Db.execnonquery (SQL)//execute custom SQL ...



Android xutils Frame (i) dbutils

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.