Я играю с некоторыми довольно большими базами данных и делаю программу, объединяющую кучу из них для повышения эффективности. При объединении с этим кодом python:
select = SQL_EXECUTE("SELECT routes.route_id, route_short_name, route_long_name, route_desc, route_type, route_url, route_text_color, trips.trip_id, arrival_time, departure_time, stops.stop_id, stop_sequence, pickup_type, drop_off_type, stop_code, stop_name, stop_desc, stop_lat, stop_lon, zone_id, stop_url, location_type, service_id, trip_headsign, direction_id, block_id FROM stops JOIN stop_times ON stops.stop_id = stop_times.stop_id JOIN trips ON trips.trip_id = stop_times.trip_id JOIN routes ON trips.route_id = routes.route_id")
for row in select:
SQL_EXECUTE("INSERT INTO joined(route_id, route_short_name, route_long_name, route_desc, route_type, route_url, route_text_color, trip_id, arrival_time, departure_time, stop_id, stop_sequence, pickup_type, drop_off_type, stop_id, stop_code, stop_name, stop_desc, stop_lat, stop_lon, zone_id, stop_url, location_type, route_id, service_id, trip_id, trip_headsign, direction_id, block_id) VALUES(:route_id, :route_short_name, :route_long_name, :route_desc, :route_type, :route_url, :route_text_color, :trip_id, :arrival_time, :departure_time, :stop_id, :stop_sequence, :pickup_type, :drop_off_type, :stop_id, :stop_code, :stop_name, :stop_desc, :stop_lat, :stop_lon, :zone_id, :stop_url, :location_type, :route_id, :service_id, :trip_id, :trip_headsign, :direction_id, :block_id)"
, route_id = row['route_id'], route_short_name = row['route_short_name'], route_long_name = row['route_long_name'], route_desc = row['route_desc'], route_type = row['route_type'], route_url = row['route_url'], route_text_color = row['route_text_color'], trip_id = row['trip_id'], arrival_time = row['arrival_time'], departure_time = row['departure_time'], stop_id = row['stop_id'], stop_sequence = row['stop_sequence'], pickup_type = row['pickup_type'], drop_off_type = row['drop_off_type'], stop_code = row['stop_code'], stop_name = row['stop_name'], stop_desc = row['stop_desc'], stop_lat = row['stop_lat'], stop_lon = row['stop_lon'], zone_id = row['zone_id'], stop_url = row['stop_url'], location_type = row['location_type'], service_id = row['service_id'], trip_headsign = row['trip_headsign'], direction_id = row['direction_id'], block_id = row['block_id'])
, где SQL_EXECUTE:
# Configure the SQL database
engine = sqlalchemy.create_engine("sqlite:///"+ dbFile)
# A function to execute SQL
def SQL_EXECUTE(statement, **params):
con = engine.connect()
statement = sqlalchemy.text(statement)
toReturn = con.execute(statement, params)
return toReturn
, здесь также есть оператор create (например, это длинный BIT, но все это стандарт GTFS в 1 таблицу только для тестирования):
CREATE TABLE "joined"(
"route_id" TEXT,
"route_short_name" INTEGER,
"route_long_name" TEXT,
"route_desc" TEXT,
"route_type" INTEGER,
"route_url" TEXT,
"route_color" TEXT,
"route_text_color" TEXT,
"shape_id" INTEGER,
"shape_pt_lat" REAL,
"shape_pt_lon" REAL,
"shape_pt_sequence" INTEGER,
"trip_id" TEXT,
"arrival_time" TEXT,
"departure_time" TEXT,
"stop_sequence" INTEGER,
"pickup_type" INTEGER,
"drop_off_type" INTEGER,
"stop_id" TEXT,
"stop_code" INTEGER,
"stop_name" TEXT,
"stop_desc" TEXT,
"stop_lat" REAL,
"stop_lon" REAL,
"zone_id" TEXT,
"stop_url" TEXT,
"location_type" INTEGER,
"service_id" TEXT,
"trip_headsign" TEXT,
"direction_id" INTEGER,
"block_id" INTEGER
)
Я думаю, что получаю эту ошибку: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked
потому что то, что я пытаюсь ВСТАВИТЬ, слишком велико, как мне это исправить?