cyp++ hat geschrieben:gibt es in SQL denn float?
Hi cyp++!
http://docs.python.org/lib/node346.html
Hier hast du mal einen Prototypen, der auch mit Timestamps klar kommt.
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
try:
import sqlite3
except ImportError:
from pysqlite2 import dbapi2 as sqlite3
import datetime
# Connection so erstellen, dass DATE- und TIMESTAMP-Felder erkannt werden.
conn = sqlite3.connect(
":memory:",
detect_types = sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES
)
# weights-Tabelle erstellen
sql = """
CREATE TABLE weights (
id INTEGER PRIMARY KEY,
timestamp TIMESTAMP,
weight REAL
)
"""
conn.execute(sql)
conn.commit()
# Index mit dem Feld timestamp erstellen
sql = """
CREATE INDEX ix_weights_timestamp
ON weights (timestamp)
"""
conn.execute(sql)
conn.commit()
# Einen Datensatz in die Tabelle weights schreiben
sql = """
INSERT INTO weights (timestamp, weight) VALUES (?, ?)
"""
conn.execute(
sql, (datetime.datetime.now(), 100)
)
conn.commit()
# Zwei Datensätze in die Tabelle weights schreiben
conn.executemany(
sql, (
(datetime.datetime.now(), 90),
(datetime.datetime.now(), 80),
)
)
# Alle Datensätze der Tabelle weights auslesen
sql = """
SELECT * FROM weights
"""
cur = conn.cursor()
cur.execute(sql)
for row in cur:
print row # --> (1, datetime.datetime(2007, 4, 29, 20, 33, 47, 781000), 100.0)
Code: Alles auswählen
(1, datetime.datetime(2007, 4, 29, 22, 57, 24, 781000), 100.0)
(2, datetime.datetime(2007, 4, 29, 22, 57, 24, 781000), 90.0)
(3, datetime.datetime(2007, 4, 29, 22, 57, 24, 781000), 80.0)
mfg
Gerold
