Android学习笔记(十七)——数据库操作(下)

时间:2022-03-09 22:54:11

  //此系列博文是《第一行Android代码》的学习笔记,如有错漏,欢迎指正!

  这一次我们来试一试升级数据库,并进行数据库的CRUD操作,其中, C 代表添加(Create) ,R 代表查询(Retrieve) ,U代表更新(Update) ,D代表删除(Delete) 。每一种操作各自对应着一种 SQL命令。前面我们已经知道,调用 SQLiteOpenHelper的 getReadableDatabase()或 getWritableDatabase()方法是可以用于创建和升级数据库的, 不仅如此, 这两个方法还都会返回一个SQLiteDatabase对象,借助这个对象就可以对数据进行 CRUD 操作了。

一、升级数据库:
  假如我们已经有了一个BookStores用于储存书籍,现在我们想再建一个Category用于储存书籍的分类,代码如下:

 public class MyDatabaseHelper extends SQLiteOpenHelper {
public static final String CREATE_BOOK = "create table Book ("
+ "id integer primary key autoincrement, "
+ "author text, "
+ "price real, "
+ "pages integer, "
+ "name text)";
public static final String CREATE_CATEGORY = "create table Category ("
+ "id integer primary key autoincrement, "
+ "category_name text, "
+ "category_code integer)";
private Context mContext;
public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_BOOK);
db.execSQL(CREATE_CATEGORY);
Toast.makeText(mContext, "Create succeeded", Toast.LENGTH_SHORT).
show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

  当我们启动程序时,会发现Category并没有被建立。因为此时 BookStore.db 数据库已经存在了,之后不管我们怎样点击 Create database 按钮,MyDatabaseHelper 中的 onCreate()方法都不会再次执行,因此新添加的表也就无法得到创建了。

  我们有一个简单而粗暴的方法来解决这个问题:只需要先将程序卸载掉,然后重新运行。这时BookStore.db 数据库已经不存在了,如果再点击 Create database 按钮,MyDatabaseHelper 中的 onCreate()方法就会执行,这时 Category表就可以创建成功了。这种方法显然过于极端,所以我们选择使用onUpdate()方法:

 @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists Book");
db.execSQL("drop table if exists Category");
onCreate(db);
}

   onUpgrade()方法中执行了两条 DROP 语句,如果发现数据库中已经存在 Book 表或 Category 表了,就将这两张表删除掉,然后再调用 onCreate()方法去重新创建。这里先将已经存在的表删除掉,是因为如果在创建表时发现这张表已经存在了,就会直接报错。

   为了让onUpgrade()方法能够执行,我们得使用SQLiteOpenHelper 的构造方法里接收的第四个参数,它表示当前数据库的版本号,之前我们传入的是 1,现在只要传入一个比 1 大的数, 就可以让 onUpgrade()方法得到执行了。代码如下:

dbHelper = new MyDatabaseHelper(this, "BookStore.db", null, 2);

  这样我们就能成功新建Category了。启动程序后按下按钮,然后在 adb shell中打开 BookStore.db 数据库,然后键入.table 命令,结果所下所示:

  可以看到此时数据库中有三张表,android_metadata 表是每个数据库中都会自动生成的,不用管它,另外键入.schema 命令便可以查看一下建表语句。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAp8AAACHCAIAAADfkKWAAAAgAElEQVR4nO2dWXccNdrH60swM1nscO+P8BKSEAhD0lmcLzBZCRM6nATC4qzYCQzlfel2t9vuth2nzJeAod9AFiA4tmM7XMIw4CUz552Zq7l8L6q6WlJJKklV1Yv9/x0OJ66ukh6pVPrrUan0WC+++OLGxsZogIWFhePHj1vNQsou26ktlK+UtrRTdtJtSSUdW4kTtLPRaMh2AgBoZP773//+8ssvq6ur//znP/+P4F//+pf7f59///vf//nPfzY2No4fP/7s2bO7d+/OzMxYrrrncrnmVndgWZZlpexyuVyOT38DxKTuidsJAABNThR1v3v3blXdGYHfqupe0Z1yuRzJr4wrHY38OFKZspNW0MbKF8RL7Pcx1rkfFWrUPmternoT0r+1pZ3a9Hsx02D3MU51JwW+hurelnZqqYNqxDVrXJvZ57a0w80kaZVttHxBvDS7CtasfTaYKlSolD+5sbCgf4tB3WvtH1mW1XD30VjdHceprbrz2wF1NGU3jL4np+4J6L3w4VXpxSLY03D5gniJ/T7WtvesXftsMFWo4FVAgo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/fe+/di5cuXrx48eKlS5cuvXvp3Xfv3bu3f/9+JRPkngQAAAAANDFQ93379j18+Kizs+v27U+s3//+93/729/SF9Ln3z7/5/Pnz58/f/7tt8+/nf7qq/LevfuUzdBZ5w0AAAAAKQbq/vKePffv37967fqNmx9bv/vd737++edz5948c/bMmTNnzp49e/bNN8++ee7LL//68st76l06AAAAYCtioO67d+/++utvPuq4cvXqNeuFF1746aefTp85ffLUyZMnT548derU6dOnz5z94osvdu9+ud6l4+GvV1Je967ztpF8C6r5TZRWXqK1BjHR7HMpzW4/AABExEDdX3rppXv3vv7gw486rlz11P3U6VMnTpz404k/nfAE/swXX3zx0u7d9S4dj2TVnbwwOXU3+l5Kh2ZXx2a3HwAAImKg7v/z0kv37t17/4MPP+q4Yr3wwgs//fzTmTOnT548ceKEK+6nT5+pqHtwDbzxJ0dxwd21RnZywuquZY9u4nWkFvex4SsBAADqhLm6v//BRx0d3nv3N988e/r0qVOnT50+c9p99/7Fl1/u3v2yiTpC3WNMvI5A3QEAoH5EmJn/sKPjirdm/u23z7/11rlz5948d+7cW2+99daf//zXr756ec8eoTp6x6uuvZ2yuB8Bk/035wv5Svr+lTG/gubbKbaH+i24CZ1/hakscfYDoHcFilo/gq+nJfVA3TS3XOL7KLKHbie8rQzJlCTtJPSrf279KJYLAACaBrNVdd98803HlStXr16z/vCHP/zyyy+XLl18550L6fTbFy6kL1y4cOGdd8rl/927b59c3f3OlDpLYTtNUSw1k61V5Yjt5NtDXciquyimiZFVnPxEe96Z1I9AYAP1IN5nh3sfRfaI1V34Bl3uu+vsCahXLgAAaAYM1H3P3r33Hzy4dv36jZs3re3bt/36668dH334wfuXL7/33uXL712+fPny++9//fXX+/fvD/iaVHSWat/Mdudh+8aHx2qLCaGdAnuoC3kbyPNKY2RVaBST6n71Jjnx1J1XXnEGYnUP3QqdyFxcU1rqrlg/KuUCAIBmwEDdX3nllUePHnXdunX79ifWjh07fvvtt87Oj29cv3792rVr165eu3bt6tWr9x88OHDgQNjMf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方法,这个方法就是专门用于添加数据的。它接收三个参数,第一个参数是表名,我们希望向哪张表里添加数据,这里就传入该表的名字。第二个参数用于在未指定添加数据的情况下给某些可为空的列自动赋值 NULL, 一般我们用不到这个功能, 直接传入 null 即可。 第三个参数是一个 ContentValues 对象, 它提供了一系列的 put()方法重载,用于向 ContentValues 中添加数据,只需要将表中的每个列名以及相应的待添加数据传入即可。现在我们就在BookStores中添加两本书,首先我们添加一个Button元素:

 <Button
android:id="@+id/add_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add data"
/>

  然后在主活动中修改代码如下:

  Button addData = (Button) findViewById(R.id.add_data);
addData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();// 开始组装第一条数据
values.put("name", "Let's learn Android");
values.put("author", "Doctor ha");
values.put("pages", 454);
values.put("price", 16.96);
db.insert("Book", null, values); // 插入第一条数据
values.clear();// 开始组装第二条数据
values.put("name", "Why I give in learning Android");
values.put("author", "Doctor ha");
values.put("pages", 510);
values.put("price", 19.95);
db.insert("Book", null, values); // 插入第二条数据
}
});

  在添加数据按钮的点击事件里面,我们先获取到了 SQLiteDatabase 对象,然后使用ContentValues来对要添加的数据进行组装。 如果你比较细心的话应该会发现, 这里只对 Book表里其中四列的数据进行了组装,id那一列没并没给它赋值。这是因为在前面创建表的时候我们就将 id 列设置为自增长了,它的值会在入库的时候自动生成,所以不需要手动给它赋值了。 接下来调用了 insert()方法将数据添加到表当中, 注意这里我们实际上添加了两条数据,上述代码中使用 ContentValues 分别组装了两次不同的内容,并调用了两次 insert()方法。

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqcAAABzCAIAAAAqtzxDAAAgAElEQVR4nO2dW28jyXXH+TG83s3jAgb04g/gxLOakTTS8NXPRuDET0SQi3d3dBfZ3SSbl+ZdGgPJQwIwgWMHcT6BJ3MTKVGUZr+Cg52L4fV6LoYf81B9qao+p7qru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Q6DvvTjcPOcupHTr3oNIL4vhG/WP3gxm8UnbpggdWThn3QsPdrlb1aZY+VWtXaqVo7FWunau5UraAoq+Ud9lO1vMMVulum1fJuxdqpWDsVc7tsblvGfasUhLIhB6v0pVn60jj6Qgyfm8UvjOIXRvELs/ilH6zSl1Yp+NMscceN+2Vzp2LtVsu7tcp+wz5ssprjGB3H7LYsVmGQGwoIfbkyCPXhuAdXJ3YXH8vRqkiDIHczuGsBwa1vLavTMjuO0WqUnHqxWTusVw9qlX27vFe1divmTtncLhvblnm/bGyXjftlc7tiuaFsesHN/CCw/LT8IBZTxdwWw04obIeDW0+AsFu1xNO5X92aVtmrQYFvVUI2d6vWLniWH+qqX3c546xBc/2pVXZrQkvFB9kx/8RqedcusxP3G3YQ6tV96S6zg5gs8kGzdtDgg9ueCE1KIzDL2u3DRnC/s5bTbzyLHcfoOAZTCvZvt2V2W1a3bXXbVq9tsSaUNWteWxrcDp7cWJ2W2W0xI6zRM1oNo9UosdBuGu2mye64bsvqdSy3ce6W/TtCqv+9Trnbtjots9u2um6jXRl0K8c9+6TvBl8c+ZuXk1EWrfZgUHswqD8Y1B4MaidusI/d0+2fnzT/HxQ/5XQPSRCdAAAAAElFTkSuQmCC" alt="" />

  可以看到两本书都已经储存在数据库里了。(注意,SQL语句句末须加分号)

三、更新数据:

  SQLiteDatabase 中也是提供了一个非常好用的 update()方法用于对数据进行更新,这个方法接收四个参数,第一个参数和 insert()方法一样,也是表名,在这里指定去更新哪张表里的数据。第二个参数是 ContentValues 对象,要把更新数据在这里组装进去。第三、第四个参数用于去约束更新某一行或某几行中的数据,不指定的话默认就是更新所有行。
  接下来我们仍然是在Database项目的基础上修改, 体会一下更新数据的具体用法。比如说刚才添加到数据库里的第一本书,我们现在尝试更新它的价格,首先添加一个button:

 <Button
android:id="@+id/update_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update data"
/>

  然后在主活动中添加下列代码:

 Button updateData = (Button) findViewById(R.id.update_data);
updateData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("price", 10.99);
db.update("Book", values, "name = ?", new String[]{"Let's learn Android" });
}
});

  这里在更新数据按钮的点击事件里面构建了一个 ContentValues 对象,并且只给它指定了一组数据, 说明我们只是想把价格这一列的数据更新成 10.99。 然后调用了 SQLiteDatabase的 update()方法去执行具体的更新操作,可以看到,这里使用了第三、第四个参数来指定具体更新哪几行。第三个参数对应的是 SQL 语句的 where 部分,表示去更新所有 name 等于?的行,而?是一个占位符,可以通过第四个参数提供的一个字符串数组为第三个参数中的每个占位符指定相应的内容。

  运行之后效果如下:

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqEAAACLCAIAAADeaNdwAAAgAElEQVR4nO2d6V8TybrH+//hP7hnrjrquEZZ/oKRXYiACztJSMLWIGtCgKCe0Zn8FWfuFR33UYGgzltRXAj6ueecV+flfdFJp5d6qrsqHZLA7/vinLFT/dRT1U39+qlV+f79+69mfvv1t7/++quurk4BAAAAwL7zn//85+PHj1++fPn+/fv/GfjnP/+p/a/Ov/71r3//+9+ZTKauru6vv/76zYzy/ft3y6VUKgWNBwAAAEqFnMa/e/fOWeN/+w1xPAAAAFAyvNT4lI0iaXyVP7W2lvJXeW54n6h0/wEAAFQE0hr/66+/liyOr3SNLKL/PnVNxzkHY2q39yiKVgBWSuo6M6GO6mP7ZL7OtM+xQ8G2L1Zvsv7zzBVUn6T/Jkdd2KLTy5QLAFBq5DT+7du39+7dM06wc9R4i5yksvkb2pR8g1LlT4m2JO5bw4NNVVWuDnyq4HdElT/lWOmGp2iyTV0n8/L5qvK55u8xPEbTE6XsU3Z4ZWTZF603Uf8pvKpP0v8qf0r0JXD42MBfGgCVhGca/+3bN8ulX3/99d27d3V1dax2QW8udFkxtE3QeA8QrRGf6lzlOSWx6iB13a2fuZx9qvG55//lxr6bl4ayb7UjUgY3/pP3Fqk+vdZ40XIBAMoFaY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52bm52dm52dnZmdnZG+fr168zMzMzMzPT09LR2Us3s7OvXr30+H70S1rh+hjXITkXn7L0pHDZute+Lh8AfAADAAUZC4y9evLi+vh6Lx+LxWDwei8VisdiCkslkFhfj8dwF7Xj5jY2NixcvkpPkzMLM3gS1II03b0/JPHICSg8AAOCAIqHx1dXVm5ubS3kSS0sJZW9vL5lMJpPJlWRyeWVlZWVleXk5nU7X1NRks9I7zU297MXUeNsWukxB15QenfcAAAAOGBIaX1tbm06nV8woe3t7t3Ksrq6u3rq1urq6tbVVW1trytAY0hdb451OtkIcDwAA4AAjofF1dbVbW1urZpS9vb3bOnfuaP+f1XifnziH1KDBzBFy9xpPDPlT54BhPB4AAMCBR0rj67a2tm6ZMWv87du3b9++detWTuNVsrvcMK3eV0gcT54vxzp3S3BevW3afhb3FgAAAID9x0uNT+rkovutra38eLwTZbvEHRoPAACgEpHWeEvQrs2rX1xMJBKJREKbi7e8nE6nq6urXboCjQcAAAA8pJA43qTxX3e/zs7Ozs7Nzc3Nz8/PLywsLMTi6xsbFy5cdOkKNB4AAADwkAL76vMa/+XLF1VV1cnJycnJyampqZvT0zMzr16/Pu/DojQAAACgBHim8Z8/fw5HIpFoNDoyMjo6NjY+MaFOvnz58uzZc6UuIwAAAHAYKXzOXVbjd3Z2BgYHhwKBQDAYDA2HI9HoyOjzF3+ePnO21GUEAAAADiOeafzHnZ2e3t7evr6+/oGBwaFAMBQKR549f3Hq9JlSlxEAAAA4jHi2du7jx4/Xb9zo7unp7unt7e8fGAoEQuGnz5+fOnW61GUEAAAADiOeafyHjx+v3bh+o7u7u6enty+r8c+g8QAAAECJ8D6O7+3r7xsYGAwE0VcPAAAAlBAvNb6nt7evv38gOxwfDkdHMOcOAAAAKBWeafzOzo4m70OBYDA0HI5GR8bGX/z58sxZaDwAAABQAjzT+E+fPgVDodDwcDgciURHRsfGx7X18efOl7qMAAAAwGHEK43/f2umCAvXbI7rAAAAAElFTkSuQmCC" alt="" />  

  可以看到第一本书的价格已被更新了。

四、删除数据:
  SQLiteDatabase 中提供了一个 delete()方法专门用于删除数据,这个方法接收三个参数,第一个参数仍然是表名,这个已经没什么好说的了,第二、第三个参数又是用于去约束删除某一行或某几行的数据,不指定的话默认就是删除所有行。同样的,我们先声明一个button:

 <Button
android:id="@+id/delete_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete data"
/>

  接着在主活动中添加如下代码:

 Button deleteButton = (Button) findViewById(R.id.delete_data);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.delete("Book", "pages > ?", new String[]{"500" });
}
});

   我们在删除按钮的点击事件里指明去删除 Book表中的数据, 并且通过第二、第三个参数来指定仅删除那些页数超过 500页的书籍。

   运行效果如下:

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqUAAABVCAIAAAD/twpVAAAZ7klEQVR4nO2d23MURfvH569ATgEupOqtyo0XXgkKCCLowiapssqirPIOIqwmIEGSbM6BZCGJOW4SSII/q/bCKrnDO5X4Qw7R8Ca7Cf+AHJJsEJGA5eV7Mbuz3T399EzPzmZ3k++nLEpmZ555umfo7zx9eNpovnFjfHy8tbV18+bNT548aW1tbWlpbm5qampqamxsbGhsvHP3zoEDBwwAAAAArDr//vvvw4cPFxYW/vzzz78Ynj9/bv5p8ffff7948SKZTL61a9ePP/1UefLkqdDnX1RVnT5z5syZL43jVzi9b2lpac7IfQ71vjQUm5yMhUp9N7xKFLv/AAAAigIPer/77bd/vnkz9PkXVdXVp8+cOXv27NmzNYZxqNmm900mjU1NjU1Nd+/ePfAe9F4kh/4HIpMWzndgz3Z7jWGYBZCdSR2XnmgRCch94o9L7SvsUMjt69WbV/9V5rKqT9J/zlEXtujzvZQLAJBvPOj9nj17Jn/55fSZL788e7bm3Lmvvjp//vx545BhGHuqJfF9c3Nzc3NzS/O9e/feO/ieYRg2aYmlfGHal0zjUhqK6bYq7lvGtU1paboOAhHNb4rSUMyx0pmn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ePHu7q6Xr16xep9PB63eutNRL1nlX5sbGx8fDyt91SGDjYhiGxQnora5flAqJH+1Jn2fHzoEAAAALCGkcb3H3300aefflpbWxuLxW7evCnE9xUVFfF4nB2aHxkZyej9jh07lpeXxxkmJiYmJiYePHhQUVFBTrDjRVoi2dnqvcP+ZrbEdwAAAMDawT5+b0p+TU3Nd999Nz09bYo9O35fUVGRSCRGGEZHR93rvWEYsv3KeDn2X+9V+5vxxpAgFAAAwJrD1PvFxcVnz55ZU/NWVlZevXr1/fffW2LvVu9bWlosvZ9Ic+3atWvXrnF6b8KG+rnWe8V+a9bPiO8BAACsUUy9X15e/uuvv/5mePny5T///PPy5UvryIsXL1ZWViy9H+VR6T0X35P7lTF6LB1Rd6/3xBQBar81jN8DAABY85h6/+zZM1PRFaysrOjpvSD5ab2n9ytjpucHsonv6f3TJPubYX4+AACAdYCp98+fP7eru6XxLA56L4zfs3o/Pz8v9ufTYAk9AAAA4COm3tul/eXLl+afAm713lqGZwG9BwAAAPKFqfd2Xacg9f6HH36YmJiw9P6qjbm5uVS+HRdA7wEAAAAfMfU+qYNU7/8Hv0oJo0QSAKQAAAAASUVORK5CYII=" alt="" />

  可以看到第二本书的数据已被删除了。

五、查询数据:

  SQL的全称是 Structured Query Language,它的大部分功能是用于查询,其他的功能只是小部分,所以查询数据会比较复杂。Android中使用query()方法来对数据进行查 询,这个方法的参数非常复杂,最短的一个方法重载也需要传入七个参数:

  第一个参数是表名,表示我们希望从哪张表中查询数据;

  第二个参数用于指定去查询哪几列,如果不指定则默认查询所有列;

  第三、第四个参数用于去约束查询某一行或某几行的数据,不指定则默认是查询所有行的数据;

  第五个参数用于指定需要去 group by的列,不指定则表示不对查询结果进行 group by操作;

  第六个参数用于对 group by之后的数据进行进一步的过滤,不指定则表示不进行过滤;

  第七个参数用于指定查询结果的排序方式,不指定则表示使用默认的排序方式。

   虽然 query()方法的参数非常多,但我们不必为每条查询语句都指定上所有的参数,多数情况下只需要传入少数几个参数就可以完成查询操作了。调用 query()方法后会返回一个 Cursor对象,查询到的所有数据都将从这个对象中取出。下面我们来实践一下,首先添加一个button:

  接着在主活动中添加代码如下:

 Button queryButton = (Button) findViewById(R.id.query_data);
queryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
// 查询Book 表中所有的数据
Cursor cursor = db.query("Book", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
// 遍历Cursor 对象,取出数据并打印
String name = cursor.getString(cursor.getColumnIndex("name"));
String author = cursor.getString(cursor.getColumnIndex("author"));
int pages = cursor.getInt(cursor.getColumnIndex("pages"));
double price = cursor.getDouble(cursor.getColumnIndex("price"));
Log.d("MainActivity", "book name is " + name);
Log.d("MainActivity", "book author is " + author);
Log.d("MainActivity", "book pages is " + pages);
Log.d("MainActivity", "book price is " + price);
} while (cursor.moveToNext());
}
cursor.close();
}
});

   可以看到,我们首先在查询按钮的点击事件里面调用了 SQLiteDatabase 的 query()方法去查询数据。这里的 query()方法非常简单,只是使用了第一个参数指明去查询 Book 表,后面的参数全部为 null。这就表示希望查询这张表中的所有数据。 查询完之后就得到了一个 Cursor 对象, 接着我们调用它的 moveToFirst()方法将数据的指针移动到第一行的位置,然后进入了一个循环当中,去遍历查询到的每一行数据。在这个循环中可以通过 Cursor 的 getColumnIndex()方法获取到某一列在表中对应的位置索引,然后将这个索引传入到相应的取值方法中,就可以得到从数据库中读取到的数据了。 接着我们使用 Log 的方式将取出的数据打印出来,借此来检查一下读取工作有没有成功完成。最后别忘了调用 close()方法来关闭 Cursor。

  程序运行效果如下:

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApMAAABSCAIAAACHX8iSAAAZaElEQVR4nO1dPXbjOAxOq7fv7T51auImbiIfwP0qrl1tkSmiZt2u0/kU6xNs6VMkl9tCEkXij5Bie+zJ91UzCkmAAEQQIC08/PXXXysAAAAAAO4ED/DcAAAAAHBHgOcGAAAAgHsCPDcAAAAA3BPguQEA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o7pT/Dcq2irGtaESasocC64suX1ui13Y2CnXlIbVvyVL/fCe/VP8p474eePP1+MdWEY0+LH87Ynlm3M1IjdHTPV+WctTZ4vR4vcTTOGTfNpWc8ttOl2ZuEe4jxaqveiQRttQ6gLQnaMrMozR10Zh0R+w1ugrbOSP4s12DdYH4pxx+OahbzF2SdxnmhgHjvsOIwl7+mV1ZdHg+5/nArfhT5j72VINW2Q0bLV0bwwmHpr74rd92XrD36tcE2YN9SiXCv5E0d89rncHhbxDTU2jtFr5d4wxvyMi7tuPZyfOOslchhbcPCFnGcndc9M6c6XUc/yfFFaSuQ3pMualscoT1/w3CRMmUdLit3zqzOnLplHRN0RrdZNm3EJJodVqgLPTzCyGhwlvzss89IwPXdiNl2YSPXFpSEbVbcJSFI7+qYtGcfSlyGf6TH3R9nUxp0sQ6dis+G/ooVPi567/1bKC2v08qzYhkUZKxJwdkz4VRg/eIu6RBvDcced+Y2B0qslJ2Erxf7So8qBVnw6Jb0VhJ/+NEgPj8ZfhY3rlD5TZYfrnKnwZDxGHUcmPF+Tlng3LUqXDZEcPXtWvWmqKcG7k83iXFrsN3Jhsu+fD3//+/soijY+MoypyytvN87uNB5exiMnyd6P8eQybfP0/Fbt6MvF2rxUIc9ETkCVVyyxhHEnd5J+JrCptuntS8aheK48Suyf/37b96fFyb0Epi8iDfF9X6U/+NTaEKkK1pKLAeq6FSRvnnPHzFTKOTcRfnI3iJo9e6hZuGchTQJo9QeB+V76IcVKWn/sFQm4BPAlFsAL7Q7/JSnms3auQWatKWehflO4vgaviZvS12yrAwAP4LmBW4TnlG7COBMDgnNRB66DW9PXPKsDAD/guQEAAADgngDPDQAAAAD3BHhuAAAAALgnwHMDAAAAwD0BnhsAAAAA7gnw3AAAAABwT4DnBgAAAIB7Ajw3AAAAANwT4LkBAAAA4J7wP32qa27KtwGhAAAAAElFTkSuQmCC" alt="" />

  在Android Monitor中可以看到第一本书的所有数据。

  //End.