2 weeks ago
2 weeks ago - last edited 2 weeks ago
ODBC:
JDBC:
EmbedPy is also an option which has a lot of flexibility.
Some example of Pandas/PyODBC/SQLAlchemy usage below
// https://github.com/KxSystems/embedPy
system"l p.q";
// https://github.com/KxSystems/ml
system"l ml/ml.q";
.ml.loadfile`:init.q;
odbc:.p.import[`pyodbc];
pd:.p.import[`pandas];
connectString:";" sv {string[x],"=",y}(.)/:(
(`Driver;"{ODBC Driver 17 for SQL Server}");
(`Server;"server.domain.com\\DB01");
(`Database;"Data");
(`UID;"KX");
(`PWD;"password")
);
connSqlServer:odbc[`:connect][connectString];
data:.ml.df2tab pd[`:read_sql]["SELECT * FROM tableName";connSqlServer];
cursor:connSqlServer[`:cursor][];
cursor[`:execute]["TRUNCATE FROM tableName"];
connSqlServer[`:commit][];
sa:.p.import`sqlalchemy;
engine:sa[`:create_engine]["mssql+pyodbc://KX:password@server.domain.com\\DB01/Data?driver=ODBC+Driver+17+for+SQL+Server"];
df:.ml.tab2df[data]; //Data to publish
df[`:to_sql]["tableName";engine; `if_exists pykw `append;`index pykw 0b];
2 weeks ago - last edited 2 weeks ago
ODBC:
JDBC:
EmbedPy is also an option which has a lot of flexibility.
Some example of Pandas/PyODBC/SQLAlchemy usage below
// https://github.com/KxSystems/embedPy
system"l p.q";
// https://github.com/KxSystems/ml
system"l ml/ml.q";
.ml.loadfile`:init.q;
odbc:.p.import[`pyodbc];
pd:.p.import[`pandas];
connectString:";" sv {string[x],"=",y}(.)/:(
(`Driver;"{ODBC Driver 17 for SQL Server}");
(`Server;"server.domain.com\\DB01");
(`Database;"Data");
(`UID;"KX");
(`PWD;"password")
);
connSqlServer:odbc[`:connect][connectString];
data:.ml.df2tab pd[`:read_sql]["SELECT * FROM tableName";connSqlServer];
cursor:connSqlServer[`:cursor][];
cursor[`:execute]["TRUNCATE FROM tableName"];
connSqlServer[`:commit][];
sa:.p.import`sqlalchemy;
engine:sa[`:create_engine]["mssql+pyodbc://KX:password@server.domain.com\\DB01/Data?driver=ODBC+Driver+17+for+SQL+Server"];
df:.ml.tab2df[data]; //Data to publish
df[`:to_sql]["tableName";engine; `if_exists pykw `append;`index pykw 0b];
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.