William Nacmanson William Nacmanson - 9 months ago 36
C++ Question

SQLite3 gets ignored with no error when PYTHON script is called from C++.

I'm using anaconda, I've installed sqlite3 using the environments.

When I run my script in the IDE, creates and populates the db no problem.

When I run the script from C++, it ignores the sqlite3 parts giving no errors and no database is created or populated. I know the script does run when called from C++ because other parts of it still function, but it just ignores the SQLite aspect.

C++ part:

string command = "C:\\Anaconda3\\python.exe C:\\CoSim2\\PYTHON\\python\\MainMaster.py " + std::to_string(minute);

Python part:

import math
import sys
import sqlite3
from pathlib import Path

conn = sqlite3.connect('CoSimTest.db')
c = conn.cursor()

def create_table():
c.execute('CREATE TABLE IF NOT EXISTS PowerSysInfo(time REAL, NumOfNodes INT, NumOfBuses INT, BusLocation TEXT, PhaseNumber INT, v1 REAL, a1 REAL, phase1 INT, v2 REAL, a2 REAL, phase2 INT, v3 REAL, a3 REAL, phase3 INT)')


Whats going on? Why does run script in the IDE work perfect, but when C++ runs the .py it just ignores the SQLite parts with no error?

Thanks in advance for the help.

Answer Source

So i thought i'd post the solution to my own question in case others have this problem. conn = sqlite3.connect('CoSimTest.db') needs a full path as the local directory changes when not running it from the ide.