Create Material Data Table

Kathryn D. Huff

This script creates a data table for use with the Cyder repository model

First, get the filename.


In [26]:
filename = "mat_data.sqlite"

Then, create a connection to the database. If it already exists, throw an exception so that you don't overwrite it.


In [27]:
import sqlite3
conn = sqlite3.connect(filename)

Once you have a Connection, you can create a Cursor object.


In [28]:
c = conn.cursor()

Create a table


In [29]:
c.execute('''CREATE TABLE clay (elem integer, d real, k_d real, s real)''')


Out[29]:
<sqlite3.Cursor at 0x1795b60>

Insert a row of data for each element. This is FAKE data... for now.


In [30]:
elements = range(1,120)
for elem in elements :
    d = elem*10.**(-6)
    k_d = elem/200.
    s = elem*2.
    str_to_execute = "{0},{1},{2},{3}".format(elem,d,k_d,s)
    c.execute("INSERT INTO clay VALUES ("+str_to_execute+")")

Save the changes and close the connection.


In [31]:
conn.commit()
conn.close()

test it


In [45]:
conn = sqlite3.connect(filename)
c = conn.cursor()
all = c.execute('''SELECT * FROM clay WHERE elem=2''')
print all.fetchone()
conn.close()


(2, 2e-06, 0.01, 4.0)

In [ ]: