In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces what the parameters of SQLite's insert method are, and the content is very detailed. Interested friends can use it for reference and hope to be helpful to you.
What do we do when we see an API parameter that we don't understand? Baidu,Google . Rarely go back to see the source code, me too, too lazy, criticize it. Bang ~
Let's take a look at a piece of code that creates a database.
Db.execSQL ("CREATE TABLE users (" + "_ id INTEGER PRIMARY KEY," + "username TEXT," + "realname TEXT," + "nsid TEXT," + "buddy_icon BLOB," + "last_update INTEGER);")
We can see that there is a type that we do not often use, BLOB, people who have studied the database must know, but I still want to say that this represents the binary data type, for example, we can store the data of a picture in it, of course, the small image can, but not the big one. For example:
AddUser (db, "Bob Lee", "Bob Lee", "45701389@N00", R.drawable.boblee_buddyicon); private void addUser (SQLiteDatabase db, String userName, String realName, String nsid, int icon) {final ContentValues values = new ContentValues (); values.put (COLUMN_USERNAME, userName); values.put (COLUMN_REALNAME, realName); values.put (COLUMN_NSID, nsid) Values.put (COLUMN_LAST_UPDATE, System.currentTimeMillis ()); final Bitmap bitmap = BitmapFactory.decodeResource (mContext.getResources (), icon); writeBitmap (values, COLUMN_BUDDY_ICON, bitmap); db.insert (TABLE_USERS, COLUMN_LAST_UPDATE, values) } static void writeBitmap (ContentValues values, String name, Bitmap bitmap) {if (bitmap! = null) {/ / Try go guesstimate how much space the icon will take when / / serialized / / to avoid unnecessary allocations/copies during the write. Int size = bitmap.getWidth () * bitmap.getHeight () * 2; ByteArrayOutputStream out = new ByteArrayOutputStream (size); try {bitmap.compress (Bitmap.CompressFormat.PNG, 100, out); out.flush (); out.close () Values.put (name, out.toByteArray ());} catch (IOException e) {/ / Ignore}
All right, no more gossip, and the point I'm going to say today is one of them:
Db.insert (TABLE_USERS, COLUMN_LAST_UPDATE, values)
For the parameter problem, please post the API description here:
Public long insert (String table, String nullColumnHack, ContentValues values) Added in API level 1Convenience method for inserting a row into the database.Parameterstable the table to insert the row intonullColumnHack optional; may be null. SQL doesn't allow inserting a completely empty row without naming at least one column name. If your provided values is empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty.values this map contains the initial column values for the row. The keys should be the column names and the values the column valuesReturnsthe row ID of the newly inserted row, or-1 if an error occurred
Well, I am sure that students who are not good at English will be like me, the description of the second parameter is still a little confused, all right, then Baidu, youdao orGoogle translation, but after all, these are translation tools, which can only give you a little knowledge, and it will take practice to get the final answer.
Here is a detailed explanation of the meaning of these three parameters in Mandarin:
Table: the name of the table for the data
NullColumnHack: when the values parameter is empty or there is no content in it, our insert will fail (the underlying database does not allow the insertion of a blank row). To prevent this, we need to specify a column name here. If you find the behavior blank line to be inserted, you will set the value of the column name to null, and then insert it into the database.
The values:ContentValues object is almost a map. Store the value in the form of a key-value pair, the key represents Column, and the value is the value of the corresponding Column.
On the SQLite insert method parameters are shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.