How do you use the cursor for reading multiple files in database in python

Tags: mysql python
Question!

In python how do you read multiple files from a mysql database using the cursor or loop one by one and store the output in a separate table?

By : user17451


Answers

Here is an example, assuming you have created the table you want to move to, with descriptive names:

>>> import MySQLdb
>>> conn = MySQLdb.connect(user='username', db='dbname')
>>> cur = conn.cursor()
>>> cur.execute('select files from old_table where conditions=met')
>>> a = cur.fetchall()
>>> for item in a:
...     cur.execute('update new_table set new_field = %s' % item) # `item` should be tuple with one value, else use "(item,)" with comma
By : unmounted


I don't understand your question (what are files?, what's your table structure?), but here goes a simple sample:

>>> import MySQLdb
>>> conn = MySQLdb.connect(host="localhost",
                           user="root",
                           password="merlin",
                           db="files")
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT * FROM files")
5L
>>> rows = cursor.fetchall()
>>> cursor.execute("CREATE TABLE destination (file varchar(255))")
0L
>>> for row in rows:
...   cursor.execute("INSERT INTO destination VALUES (%s)" % row[0])
...
1L
1L
1L
1L
1L


You can split up XAML files by using a ResourceDictionary. The ResourceDictionary can be used to merge other files:

<Page.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="myresourcedictionary.xaml"/>
      <ResourceDictionary Source="myresourcedictionary2.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Page.Resources>

In the ResourceDictionary, you can also declare Styles that you can use at your elements, such that the main XAML file gets smaller.

Another possibility to get a smaller XAML file is to define your own controls that you then use in your main app.

By : EFrank


This video can help you solving your question :)
By: admin