Hallo in die Runde,
ich hatte mir vor langer Zeit ein Plugin gebastelt mit dem ich Wertpapierkurse aus eine Datenbank abrufen konnte und in einer mysql-Datenbank weiterverarbeiten konnte. Lief seit 2 Jahren problemlos.
Jetzt bei der Umstellung auf sqlite3 scheitere ich bei der Datenübernahme und bitte um Hilfe!
Ich habe den Aufbau der Datenbank in "tests" als "aaeig99_test_create_depwerte" unter CODE hinterlegt .
Hier der Fehlercode:
ich hatte mir vor langer Zeit ein Plugin gebastelt mit dem ich Wertpapierkurse aus eine Datenbank abrufen konnte und in einer mysql-Datenbank weiterverarbeiten konnte. Lief seit 2 Jahren problemlos.
Jetzt bei der Umstellung auf sqlite3 scheitere ich bei der Datenübernahme und bitte um Hilfe!
Ich habe den Aufbau der Datenbank in "tests" als "aaeig99_test_create_depwerte" unter CODE hinterlegt .
Code:
import sqlite3
from sqlite3 import Error
#aaeig99_test_create_depotwerte.py
try:
conn = sqlite3.connect('/usr/local/smarthome/var/db/portfolio.db')
#####################
#logger.warning('=== Begin Smarthome Tests: aaeig99_test_create_depwerte.py')
###################################
# python /usr/local/smarthome/tests/test_portfolio.db
#SQLite type Python type
#NULL None
#INTEGER int
#REAL float
#TEXT depends on text_factory, str by default (????)
# varchar
my_data = [(1, 'A1HS49', 'DE000A1HS492', 'A1HS49', 1, 1, 'HVB', 1, 5, 'Anleihe auf Stufenzins ', 0, 000250.0000, 000100.0000, '5000.00, '2013-12-17', 100.25, 25062.50, '', '', 1.00, 'http://www.xyz.de/DE000A1HS492/kurs', '2022-09-11 17:12:13', 99.82, 102.50, '2018-12-11', '2017-06-27', 100.25, 120.30, 0.00, 2018-12-17, 000250.0000, 100.00, 25000.00, 62.50, 'None ', 0.00, 0.00, 0.00, 0.00, 0),
(2, 'AIR.DE', 'NL0000235190', '938914', 1, 4, 'COR2', 1, 1, 'Airbus SE Handelsplaetze ', 0, '000050.0000', '001034.6000', '20692.00', '2015-06-16', '57.76', '11551.80', '', '', '1.00', 'http://www.xyz.de/NL0000235190/kurs', '2022-07-29 12:16:00', '1.00', '140.78', '2019-04-01', '2019-04-30', '80.20', '98.02', '0.00', '2017-04-27', '000000.0000', '73.78', '14756.55', '9140.20', ' None ', '0.00','0.00','0.00','0.00','0'),
(3, '', 'DE0008471483', '847148', 1, 3, 'COR1', 1, 3, 'Allianz Aktien Europa A ', 3, '000000.0000', '000650.0000', '3529.98', '2011-06-08', '45.00', '2430.00', '', '', '1.00', 'http://www.xyz.de/DE0008471483/kurs', '0000-00-00 00:00:00', '65.37', '95.90', '2020-11-22', '2018-01-24', '62.76', '54.45', '0.00', '0000-00-00', '000000.0000', '0.00', '0.00', '1099.98', ' None ','0.00','0.00','0.00','0.00','0'),]
####??conn= sqlite3.connect('.databases.trace')
# 40 felder geprüft !!
# 10 20 30 40
cur = conn.cursor()
#Diese 40 Felder sollen in die Datenbank übernommen werden! Leider gibt es einen Syntaxfehler den ich nicht erkenne.
#Musterdatei als Grundlage genutzt
#data = [
#("Monty Python Live at the Hollywood Bowl", 1982, 7.9),
#("Monty Python's The Meaning of Life", 1983, 7.5),
#("Monty Python's Life of Brian", 1979, 8.0),]
#cur.executemany("INSERT INTO movie VALUES(?, ?, ?)", data)
################################################## depwerte result ####################################
cur = conn.cursor()
print("Successfully Connected to SQLite portfolio.db")
cursor.execute(sqlite_create_table_query)
conn.commit()
print("SQLite table depwerte created")
cursor.close()
except sqlite3.Error as error:
print("Error while creating a sqlite table depwerte", error)
finally:
if conn:
conn.close()
print("sqlite3 connection is closed")
cur.execute('''DROP TABLE if exists depwerte''')
sqlite_create_table_query = ''' "CREATE TABLE IF NOT EXISTS `depwerte` (" \
"`_index` NOT NULL PRIMARY KEY, " \
"`_ticker` TEXT(10) DEFAULT '', " \
"`_isin` TEXT(14) DEFAULT '', " \
"`_wkn` TEXT(8) DEFAULT '', " \
"`_folge` tinyint(4) DEFAULT 1 , " \
"`_intdepot` int(2) NOT NULL DEFAULT 1, " \
"`_depot` TEXT(6) DEFAULT 'HVB', " \
"`_aktiv` tinyint(4) DEFAULT 0, " \
"`_kz` tinyint(4) DEFAULT 0, " \
"`_text` TEXT(255) DEFAULT '', " \
"`_art` tinyint(4) DEFAULT 0, " \
"`_stueck` REAL(10,4) DEFAULT 0.0000, " \
"`_kurs` REAL(10,2) DEFAULT 0.00, " \
"`_aktwert` REAL(10,2) DEFAULT 0.00, " \
"`_kaufdate` date DEFAULT NULL, " \
"`_kaufkurs` REAL(10,2) DEFAULT 0.00, " \
"`_kaufwert` REAL(10,2) DEFAULT 0.00, " \
"`_boerse` TEXT(10) DEFAULT '', " \
"`_waehr` TEXT(10) DEFAULT 'EUR', " \
"`_devkurs` REAL(10,2) DEFAULT 1.00, " \
"`_html` TEXT(255) DEFAULT ' N/A', " \
"`_date` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(), " \
"`_low50` REAL(10,2) DEFAULT 999999.00, " \
"`_hoch50` REAL(10,2) DEFAULT 0.00, " \
"`_datel50` date DEFAULT NULL, " \
"`_dateh50` date DEFAULT NULL, " \
"`_limmin` REAL(10,2) DEFAULT 0.00, " \
"`_limmax` REAL(10,2) DEFAULT 99999.00, " \
"`_stoppkurs` REAL(10,2) DEFAULT 99999.00, " \
"`_verkdate` date DEFAULT NULL, " \
"`_verkstueck` REAL(10,4) DEFAULT 0.0000, " \
"`_verkkurs` REAL(10,2) DEFAULT 0.00, " \
"`_verkwert` REAL(10,2) DEFAULT 0.00, " \
"`_kursgew` REAL(10,2) DEFAULT 0.00, " \
"`_notiz` TEXT(100) DEFAULT ' ', " \
"`_wert1` REAL(10,2) DEFAULT 0.00, " \
"`_wert2` REAL(10,2) DEFAULT 0.00, " \
"`_wert3` REAL(10,2) DEFAULT 0.00, " \
"`_wert4` REAL(10,2) DEFAULT 0.00, " \
"`_zugangsart` tinyint(2) DEFAULT 0 );'''
print('=== Einfügen Daten vor execute aaeig99_test_create_depwerte.py')
cur = conn.cursor()
cur.execute(sqlite_create_table_query)
conn.commit()
cur.executemany('INSERT INTO depwerte VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',my_data);
print('We have inserted', cur.rowcount, 'records to the table.')
conn.commit()
print "SQLite table depwerte created"
cursor.close()
print('=== Einfügen Daten in test_aaeig99_depwerte.py')
select_all = "SELECT * FROM `depwerte`"
rows = cur.execute(select_all).fetchall()
#result3 = rows
conn.close
Code:
smarthome@SmartHomeNG-4-8-IP40 ../local/smarthome/tests]$ python aaeig00_test_create_depwerte.py
File "/usr/local/smarthome/tests/aaeig00_test_create_depwerte.py", line 20
my_data = [(1, 'A1HS49', 'DE000A1HS492', 'A1HS49', 1, 1, 'HVB', 1, 5, 'Anleihe auf Stufenzins ', 0, '000250.0000', '000100.0000', '25000.00', '2013-12-17', '100.25', '25062.50', '', '', '1.00', 'http://www.xyz.de/DE000A1HS492/kurs', '2022-09-11 17:12:13', '99.82', '102.50', '2018-12-11', '2017-06-27', '100.25', '120.30', '0.00', '2018-12-17', '000250.0000', '100.00', '25000.00', '62.50', ' ', '1.00', '2.00', '3.00', '4.00', '0'),
^
SyntaxError: invalid syntax
#Der Zeiger ^ wandert je Bildschirmbreite von Feld zu Feld, damit kein Hinweis auf den Fehler


Kommentar