Hi all,<br>I'd like to ask about some (probably elementary) things about the proper usage of sqlite3 in python (2.5.2; win).<br>- Are there any peculiarities with using curs.executemany(...) vs. multiple curs.execute(...) ? I read a notice, sqlite3 does internally some caching, hence both should be similarly fast, but in my case executemany(...) is quite a bit faster (probably due to the function call overhead?). Are there maybe some caveats with using  executemany? (the obvious memory consumption for the intermediate list doesn't seem to matter much in my application).<br>
 Further, I am not quite sure about the standard usage of the cursor object and also the proper commiting the transactions and closing the connection.<br> Should one create a cursor of a connection and call the execute ... methods of the cursor - <br>
or is it better to call the shortcut execute etc. methods of the Connection object directly (as suggested in the docs: <a href="http://docs.python.org/lib/node351.html">http://docs.python.org/lib/node351.html</a> (or are there specific use cases for both approaches)?<br>
<br>When the transactions should be commited? (creating, altering a table, or also selecting the results ?)<br> There seem to be some implicit handling of the transactions ( <a href="http://docs.python.org/lib/sqlite3-Controlling-Transactions.html#sqlite3-Controlling-Transactions">http://docs.python.org/lib/sqlite3-Controlling-Transactions.html#sqlite3-Controlling-Transactions</a> ); hence I am not sure about the standard usage of these methods; the same is true of connection.close() - or are these calls eventually unnecessary? <br>
<br>To give a bit more info about my use case, my (gui) app displays a set texts along with some informations on the currently visible text segments.<br> After starting a gui the texts are read from the source  files (also containing a kind of tags)  - simultaneously the tags are parsed and the corresponding values are stored in sqlite "in memory" - the column names as well as the corresponding values for given text parts are extracted dynamically from the source files.<br>
 During the whole run of the program the db should be available in order to retrieve the properties of the given text index.<br> <br>Below is a part of my code dealing with the populating of the db;, I'm sorry, it's a not runable pseudocode, however, my present code works somehow, but I'm quite sure, the implementation isn't really standard, hence I'd like to hear some comments/suggestions. (I asked some time ago about the possibility of a parametrised input of the table and column names, but this seems impossible - therefore I used the string interpolation.)<br>
<br>- the variables are defined in other parts of code before; most of the names might be self explanatory; self - custom class managing the text with its properties; text_name - name of the table;  index_col_name - a name of the special db column containing the text index; act_db_columns - list of the db columns; question_marks - a string "?, ?, ? ..." (synchronized with the length of act_db_columns); tags_seq - a nested list with the previously retrieved data for the database. <br>
<br>conn_tags_DB = sqlite3.connect(':memory:')<br>        curs = self.conn_tags_DB.cursor()<br>        curs.execute('CREATE TABLE IF NOT EXISTS "%s" ("%s", UNIQUE("%s"))' % (self.text_name, index_col_name, index_col_name))<br>
curs.execute(u'INSERT OR REPLACE INTO "%s"("%s") VALUES (?)' % (self.text_name, index_col_name), (0,))<br>        for new_col in act_db_columns[1:]: # adds the needed columns (except of  the first one: index_col_name)<br>
                curs.execute('ALTER TABLE "%s" ADD "%s" TEXT' % (self.text_name, new_col))<br>        curs.executemany('INSERT OR REPLACE INTO "%s" VALUES (%s)' % (self.text_name, question_marks), tags_seq)<br>
self.conn_tags_DB.commit()<br><br>Are there maybe any comments or hints on a more elegant/efficient solution?<br> <br>Now, what's the usual way to access the database? Is it possible/wise/standard ... to leave the connection open for the subsequent queries during the whole run of the app; could even the cursor eventually be present as a class method, or should it rather be created repeatedly with each call?  (After populating, the db shouldn't be modified, but only read.)<br>
 <br>Many thanks in advance for your help;<br> and apologies for this longer post.<br>   Greetings,<br>       Vlasta<br><br>