English 中文(简体)
履历 议题: 法典修改能够加快步伐?
原标题:Performance SQLite Issue - Can a codechange speed up things?

我使用以下代码在我的数据库中添加行文:

    public void insert(String kern, String woord) {
      SQLiteDatabase db = getWritableDatabase();

      ContentValues values = new ContentValues();
      values.put(KERN, kern);
      values.put(WOORD, woord);

      db.insertOrThrow(TABLE_NAME, null, values);
      return;

目前,我引用这段话,用以下文字在数据库中添加所有字:insert(“Fruits”),“Banana”

我怎样才能改变这一法典,以更快地开展工作? 我的思路是 for,但不知道如何执行。 感谢!

/Edit; @hovanessyan提供的解决办法能够发挥作用。 并且指出,如果你有许多线索,那么你可能面临的方法可能超过极限错误。 在这种情况下,审查另一种解决办法,即建议将数据库实际包装。 APK文档。

最佳回答

我利用了霍瓦尼扬和达米安两岸(在我到达15岁时,我再次问你+1);我提出了以下解决办法:

  1. For relatively small databases (<1,5Mb)

我利用Kingk数据库Browser建立了数据库,将其放在我的资产夹中。

之后,以下代码将数据库复制到该装置,如果该数据库尚未安装:

    boolean initialiseDatabase = (new File(DB_DESTINATION)).exists();

public void copyDB() throws IOException{ final String DB_DESTINATION = "/data/data/happyworx.nl.Flitswoorden/databases/WoordData.db";

    // Check if the database exists before copying


    Log.d("Database exist", "" + initialiseDatabase);
    Log.d("Base Context", "" + getBaseContext());

    if (initialiseDatabase == false) {

        // Open the .db file in your assets directory
        InputStream is = getBaseContext().getAssets().open("WoordData.db");


        // Copy the database into the destination
        OutputStream os = new FileOutputStream(DB_DESTINATION);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0){
            os.write(buffer, 0, length);
        }
        os.flush();

        os.close();
        is.close();
    }}

在我看来,该数据库的一部分是用户可视的。

我在《经济、社会、文化权利国际公约》中将上述准则称为:

        try {
        copyDB();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

因此,当用户发布“重新建立数据库以达到标准”(偏好屏幕)时,我刚刚将“蓝色”代码()“false”改为“false”,等待用户回到主要活动。 (负责启动和复制原始数据库)。

我试图称之为这项活动。 页: 1 它 ne了,因为它没有要求用户回到重建数据库的主要活动。 然而,我错误地认为不能静态提及非统计方法。 我不理解,但将研究这一问题。

问题回答

您可以总结一下这些话。

db.beginTransaction();
 try {
  // do all the inserts here

  //method call here, that does 1 insert; For example
  addOneEntry(kern,woord);
  ... 
  db.setTransactionSuccessful();
 } catch (SQLException e) {
         //catch exceptions
 } finally {
   db.endTransaction();
 }


 private void addOneEntry(String kern, String woord) {
   //prepare ContentValues
   //do Insert
 }

你们可以使用大宗 插入:

   ContentValues[] cvArr = new ContentValues[rows.size()];
   int i = 0;
   for (MyObject row : rows) {
    ContentValues values = new ContentValues();
    values.put(KERN, myObject.getKern());
    values.put(WOORD, myObject.getWoord);       
    cvArr[i++] = values;
    }// end for
    resolver.bulkInsert(Tasks.CONTENT_URI, cvArr);




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签