cursor

Is there a good reason for a ListView header taking up a position?

↘锁芯ラ 提交于 2019-12-05 21:27:58
问题 I've just added a header to my ListView and I have to change a bunch of code because the header essentially becomes position 0 (Meaning the Cursor indices of my CursorAdapter do not line up with the indicies of the list. They are off by 1 now). Why? This seems a bit silly to me. The only reason I can come up with is that a developer may want to access the header. Fine. Provide something like getListView().getHeader(). 回答1: For some reason the position (from the onItemClick ) is tied up with

Android database connections and cursors oh my

对着背影说爱祢 提交于 2019-12-05 19:36:22
I have read plenty of blogs and tutorials on how to create and use database connections when working with android. Although I have plenty of working examples, different implementations result in different issues. Example, I use a datasource class, Datasource and a database helper class, DBManagement . DataSource public class DataSource { // Database fields private SQLiteDatabase database; private DBManagement dbHelper; public SMSDataSource(Context context) { dbHelper = new DBManagement(context); } public void open() throws SQLException { if(database == null){ database = dbHelper

How to use server side cursors with psycopg2

坚强是说给别人听的谎言 提交于 2019-12-05 19:14:05
问题 I have a table with 4million rows and I use psycopg2 to execture a: SELECT * FROM ..WHERE query I haven't heard before of the server side cursor and I am reading its a good practice when you expect lots of results. I find the documentation a bit limited and I have some basic questions. First I declare the server-side cursor as: cur = conn.cursor('cursor-name') then I execute the query as: cur.itersize = 10000 sqlstr = "SELECT clmn1, clmn2 FROM public.table WHERE clmn1 LIKE 'At%'" cur.execute

Python, SQLite3: cursor returns duplicates when a commit intervenes

一曲冷凌霜 提交于 2019-12-05 19:05:55
This Python code creates a table, inserts three rows into it and iterates through the rows, with intervening commits before the cursor has been fully exhausted. Why does it return five rows instead of three? If the intervening commit is removed, the number of returned rows is three as expected. Or is it expected that a commit (which doesn't even touch the table in question) invalidates a cursor? Edit: Added a forgotten commit (which makes the issue disappear) and an insert to an unrelated table (which makes the issue appear again). #!/usr/bin/env python3 import sqlite3 as sq db = sq.connect('

How to improve performance of a function with cursors in PostgreSQL?

孤者浪人 提交于 2019-12-05 18:35:29
I have function with two nested cursors. The outer cursor gets payment details of a customer from the source and inserts into the target based on some business logic. The inner cursor takes the payment details of each payment, it happens one after another. The payments table has about 125000 rows, and about 335000 rows for payment details. All of these rows are to be migrated to a target table. Executing the function takes over two hours and the database CPU usage goes up to 99%. I am working with PostgreSQL 9.2. How can I improve the performance of the function? The code I am using: CREATE OR

Node Mongo Native - how to tell when a cursor is exhausted?

萝らか妹 提交于 2019-12-05 18:05:58
The documentation for the node-mongo-native collection.find() function says that it creates a cursor object which lazily returns the matching documents. Furthermore: The basic operation on a cursor is the nextObject method that fetches the next matching document from the database. The convenience methods each and toArray call nextObject until the cursor is exhausted. Unfortunately, the documentation provides no indication of how to tell when the cursor is actually exhausted. You could use the "toArray" method and use the standard array interface (e.g. the "length" method) but this solution is

cursor

拈花ヽ惹草 提交于 2019-12-05 17:29:55
css cursor对照表 css 示例 cursor: alias cursor: all-scroll cursor: cell cursor: col-resize cursor: copy cursor: crosshair cursor: default cursor: e-resize cursor: ew-resize cursor: -webkit-grab; cursor: -moz-grab; cursor: grab; cursor: -webkit-grabbing; cursor: -moz-grabbing; cursor: grabbing; cursor: help cursor: move cursor: n-resize cursor: ne-resize cursor: nesw-resize cursor: no-drop cursor: not-allowed cursor: none 空 cursor: ns-resize cursor: nw-resize cursor: nwse-resize cursor: pointer cursor: progress cursor: row-resize cursor: s-resize cursor: se-resize cursor: sw-resize cursor: text

Proper implementation of changing ListView data with CursorAdapter

梦想与她 提交于 2019-12-05 17:17:36
I have a ListView populated via a CursorAdapter. I give my user the ability to alter the data in the list. For example, the user can mark a row as being unread (the data are messages). Suppose my user marked a row unread. Would a proper implementation mark the row in the database as read and then requery the Cursor? Would a proper implementation mark the row in the database as read and then requery the Cursor? Yes, that's the right answer. The requery() will trigger an automatic update of your CursorAdapter , which will trigger an automatic update of the ListView , which will trigger an

Is there any difference between closing a cursor or a connection in SQLite?

点点圈 提交于 2019-12-05 17:02:41
I have been using always the command cur.close() once I'm done with the database: import sqlite3 conn = sqlite3.connect('mydb') cur = conn.cursor() # whatever actions in the database cur.close() However, I just saw in some cases the following approach: import sqlite3 conn = sqlite3.connect('mydb') cur = conn.cursor() # whatever actions in the database cur.close() conn.close() And in the official documentation sometimes the cursor is closed, sometimes the connection and sometimes both. My questions are: Is there any difference between cur.close() and conn.close() ? Is it enough to close one,

SQL中游标的使用

℡╲_俬逩灬. 提交于 2019-12-05 16:41:43
SQL中游标的使用 类型:   1.普通游标 只有NEXT操作   2.滚动游标 有多种操作 1.普通游标 DECLARE @username varchar(20),@UserId varchar(100) DECLARE cursor_name CURSOR FOR --定义游标 SELECT TOP 10 UserId,UserName FROM UserInfo ORDER BY UserId DESC OPEN cursor_name --打开游标 FETCH NEXT FROM cursor_name INTO @UserId,@username --抓取下一行游标数据 WHILE @@FETCH_STATUS = 0 BEGIN PRINT '用户ID:'+@UserId+' '+'用户名:'+@username FETCH NEXT FROM cursor_name INTO @UserId,@username END CLOSE cursor_name --关闭游标 DEALLOCATE cursor_name --释放游标 结果: 用户ID:zhizhi 用户名:邓鸿芝 用户ID:yuyu 用户名:魏雨 用户ID:yujie 用户名:李玉杰 用户ID:yuanyuan 用户名:王梦缘 用户ID:YOUYOU 用户名:lisi 用户ID:yiyiren 用户名