I want to create temp tables and use it later in one session. I can create it, but then when I try to use to I receive:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name #my_table
I try the same queries in SSMS and everything works correctly.
For example
...
std::shared_ptr<Poco::Data::Session> session;
...
Poco::Data::Statement createStatement(*session);
createStatement<< create_temp_table_and_insert_into_temp_table;
createStatement.execute();
Poco::Data::Statement insertStatement(*session);
insertStatement<< select_from_temp_table;
insertStatement.execute(); <- exception Invalid object name
Another example
...
std::shared_ptr<Poco::Data::Session> session;
...
*session.get() << "IF(OBJECT_ID('tempdb..#test') is not null) drop table #test;";
*session.get() << "create table #test (s1 int,s2 int ,s3 int);";
*session.get() << "insert into #test select 1,2,3";
typedef Poco::Tuple<int, int, int> testParam;
std::vector<testParam> testParams;
*session.get() << QString("select * from #test").toStdString(), Poco::Data::Keywords::into(testParams),
Poco::Data::Keywords::now;
I tried the same with qt odbc driver and queries also work. I also tried Driver={ODBC Driver 17 for SQL Server} and old driver DRIVER={SQL Server} too.
Related
I need some help with processing queries using Apache Calcite, I am currently using Planner to process my queries.
My code looks like this:
// custom config
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(rootSchema)
.sqlToRelConverterConfig(convertConfig)
.operatorTable(operatorTable)
.build();
Planner planner = Frameworks.getPlanner(frameworkConfig);
String sql = "Select id, name from t where id in (?, ?)";
SqlNode parsedSqlNode = planner.parse(sql);
SqlNode validatedSqlNode = planner.validate(parsedSqlNode);
RelRoot relRoot = planner.rel(validatedSqlNode);
PreparedStatement preparedStatement = RelRunners.run(relRoot.rel);
preparedStatement.setLong(1, 11111);
preparedStatement.setLong(2, 22222);
ResultSet resultSet = preparedStatement.executeQuery();
// ....
It works fine without SQL parameters, but there are some queries with SQL parameters.
While using SQL parameter and setting the parameter(preparedStatement.setLong), I got the following error message:
Caused by: java.sql.SQLException: parameter ordinal 1 out of range
at org.apache.calcite.avatica.Helper.createException(Helper.java:60)
at org.apache.calcite.avatica.AvaticaPreparedStatement.getParameter(AvaticaPreparedStatement.java:427)
at org.apache.calcite.avatica.AvaticaPreparedStatement.getSite(AvaticaPreparedStatement.java:434)
at org.apache.calcite.avatica.AvaticaPreparedStatement.setLong(AvaticaPreparedStatement.java:178)
SQL parameters are obviously not being handled correctly. What is the proper way to define and set SQL parameters when using Planner in a case like this?
I'm trying to load a table using SAS but getting an error. This code worked in the past, but since sybase was upgraded it doesn't work with SAS.
proc sql;
connect to odbc as db (dsn=sas_xxx uid=&user pwd=&pass insertbuff=2048connection=shared);
execute(set temporary option escape_character=on) by db;
execute(CREATE TABLE #tomatch (ID int,
DOB int,
NAME_LAST varchar(20),
NAME_FIRST varchar(15),
)) by db;
execute(LOAD TABLE #tomatch (ID, DOB, NAME_LAST, NAME_FIRST)
USING CLIENT FILE "/home/5n0rb/MIGRATE/input/FCRA/&location..csv"
QUOTES ON
ESCAPES OFF
FORMAT BCP
DELIMITED BY ','
ROW DELIMITED BY '\x0a'
SKIP 1) by db;
ERROR: CLI execute error: [SAP][ODBC Driver][SAP IQ]Syntax error - Column is not accessible in this context. --
(dflib/df_Heap.cxx 2763)
I'm using pro c/c++ in a unix environment. Inside a c function I create a simple select statement which is not inside a loop and autocommit is disabled.
This is the dynamic sql;
char sql_statement[200];
int num1, num2;
...
snprintf(sql_statement, sizeof(sql_sattement), "select column1, column2 from '%s' where num = '%d' and code_cfg = '%d'", "customer", 0, 0);
exec sql prepare instruction_to_execute from :sql_statement;
exec sql declare crs cursor for instruction_to_execute;
exec sql open crs;
exec sql fetch crs into :num1, :num2;
...
Executing this code gives me ORA-01002 error. As I said before, this code is not inside a loop and autocommit is off.
But if I write this code statically, works fine. Below the code:
EXEC SQL
SELECT column1, column2
INTO :num1, :num2
FROM CUSTOMER
where num = 0
AND code_cfg = 0;
SQL instruction is simple. For my understanding this code should be executed fine.
In SO I found some answers:
ORA-01002: fetch out of sequence C++
ORA-01002: fetch out of sequence
Hibernate error “ORA-01002” when persisting entity with custom Sequence Generator
ORA-01002: fetch out of sequence
java.sql.SQLException: ORA-01002: fetch out of sequence
When i will view the data from my mysql database " mydb " , from the table "testtable", it cant open the database.
this->model = new QSqlQueryModel();
meineView->setModel(model);
must i write it so :
model->setQuery("SELECT id, Nachname, Vorname, Ort FROM mydb");
Or so ? :
model->setQuery("SELECT `testtable`.`id`,`testtable`.`Nachname`,`testtable`.`Vorname`,`testtable`.`Ort`FROM `mydb`.`testtable`;");
what do i wrong ? when i delete this , my program works ( without views the data )
and when i can open it, how i put the data in my table ? ?
You need to call overriden method with your Database name. Because the database you are trying to open is not default database.
Try this :
model->setQuery("SELECT `testtable`.`id`,`testtable`.`Nachname`,`testtable`.`Vorname`,`testtable`.`Ort
`FROM `mydb`.`testtable`;","mydb");
First of all you need to connect to database using QSqlDatabase class. Then you can connect QSqlQueryModel to sql connection using proper sql query.
your first query is wrong because mydb is the database and this query needs table name:
SELECT id, Nachname, Vorname, Ort FROM testtable.
Second query is the option to choose when the query references multiple tables.
SELECT testable.id, testable.name, othertable.data FROM testable, othertable, WHERE testable.someRow = othertable.someRow
I'm trying to get the rpw 'AID' from the table 'Account'.
SQLCHAR AID;
wsprintf(String, "select [AID] from [Account] where [UserID] = '%s'", User);
Sql.RetCode = Sql.Execute(String);
Sql.RetCode = Sql.Fetch();
Sql.Clear();
sprintf(String, "Here my result: %s", SQL RETURN!);
MsgBox(String);
How can i get the [AID] from the table [Account] ? (For User 'idohadar')
I see that you use some object library to call ODBC function. I do not know this library but I use ODBC from "raw" API or wrap it in my classes.
Raw API is very well described on: http://www.easysoft.com/developer/languages/c/odbc-tutorial-fetching-results.html
You must prepare buffer for values then call SQLFetch() and then read from that buffer.