How can I create an in-memory database with sqlite?
<p>I'm trying to create an in-memory database using <code>sqlite3</code> in Python.</p>

<p>I created a function to create a db database file and store information in to it and that is working 100%.</p>

<p>But trying to connect with <code>:memory:</code> I've faced some problems.</p>

<p>What I'm doing is:</p>

<pre><code>import sqlite3

def execute_db(*args):
    db = sqlite3.connect(":memory:")
    cur = db.cursor()
    data = True
    try:
        args = list(args)
        args[0] = args[0].replace("%s", "?").replace(" update "," `update` ")
        args = tuple(args)
        cur.execute(*args)
        arg = args[0].split()[0].lower()
        if arg in ["update", "insert", "delete", "create"]: db.commit()
    except Exception as why:
        print why
        data = False
        db.rollback()
    db.commit()
    db.close()
    return data
</code></pre>

<ol>
<li><p>create name table</p>

<pre><code>execute_db("create table name(name text)")
</code></pre>

<p>which returned <code>True</code></p></li>
<li><p>insert some information to this table</p>

<pre><code>execute_db("insert into name values('Hello')")
</code></pre>

<p>which returned</p>

<pre><code>no such table: name
False
</code></pre></li>
</ol>

<p>Why doesn't this work? It works when I use a file:</p>

<pre><code>db = sqlite3.connect("sqlite3.db")
</code></pre>