Home » U++ Library support » U++ SQL » ODBC Assertion failed
Re: ODBC Assertion failed [message #55844 is a reply to message #55812] |
Mon, 21 December 2020 15:33   |
JeyCi
Messages: 69 Registered: July 2020
|
Member |
|
|
was this correct in your whole code?
Quote:SQL = myDB;
Sql query(myDB);
the insertion below is working for me in Sqlite3 - try to adopt the code to your MS_SQL_Server_connection (your Commit, Rollback & WasError() are included in this code, I just can not check for ms_sql_server & therefore cannot provide adopted example)... but such is my view on insertion
#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
Cout() << "Start" << EOL;
Sqlite3Session myDB; // <<<<<<<<<<<<<< ADOPT TO YOUR MS_Sql_Server.....
if(!myDB.Open(ConfigFile("DATA.db"))) {
LOG("Can't create or open database file\n");
return;
}
#ifdef _DEBUG
myDB.SetTrace();
#endif
SQL = myDB;
// ======================= initial data
String s = "[{\"A\":\"valA1\", \"B\":\"valB1\"}, {\"A\":\"valA2\", \"B\":\"valB2\"}]";
ValueMap js=ParseJSON(s); // frankly speaking ValueArray should be perhaps, but it works for me...
int jsz=js.GetCount();
// ======================= create tbl
SQL.Execute("drop table IF EXISTS tbl;");
SQL.Execute("create table IF NOT EXISTS tbl (A STRING , B STRING, PRIMARY KEY (A));");
// ======================= insert into tbl
Sql query(myDB); // (my_db)
query.SetStatement("INSERT INTO tbl ( A, B) VALUES ( ?, ?) ");
// initialize transaction
query.Begin();
// loop to insert rows
for(size_t i = 0; i < jsz; i++) {
query.SetParam(0,~js[i]["A"]);
query.SetParam(1,~js[i]["B"]);
query.Execute();
}
// error behavior
if(query.WasError()){
Cout() << query.GetLastError();
query.Rollback();
return; // false;
}
//Save data & unlock db
query.Commit();
Cout() << "Done" << EOL;
// ======================= select to console_view
if (query.Execute("SELECT * FROM tbl"))
{
Cout() << "Call succeeded" << EOL;
for (int i = 0; i < query.GetColumnCount(); ++i) {
Cout() << Format("%d: %s", i, query.GetColumnInfo(i).name) << EOL;
}
while (query.Fetch()) {
Cout() << query[0] << " ; " << query[1] << EOL;
}
}
else
{
Cout() << "Call failed" << EOL;
Cout() << SQL.GetLastError() << EOL;
}
}
if you put "valA1" to both A-key values in json-string -- you will catch
Quote:SQL logic error
p.s.
I don't know whether SqlMassInsert will be quicker, but using Transactions gives the possibility for Rollback - I am not sure about this possibility in SqlMassInsert, perhaps it is being done automatically for this class - in LOG should be seen, - but I didn't check SqlMassInsert& UseTransaction(bool b = true) == testing needed to compare the speed of 2 approaches (my & SqlMassInsert)
Wish you good luck if my code could be helpful for you... or somebody can notice some mistakes with a fresh_eye
Best regards.
[Updated on: Fri, 01 January 2021 17:08] Report message to a moderator
|
|
|
 |
|
ODBC Assertion failed
By: Giorgio on Thu, 17 December 2020 11:01
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Thu, 17 December 2020 14:09
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Thu, 17 December 2020 14:22
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Thu, 17 December 2020 15:06
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Thu, 17 December 2020 16:27
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Thu, 17 December 2020 17:44
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Fri, 18 December 2020 06:26
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Fri, 18 December 2020 08:32
|
 |
|
Re: ODBC Assertion failed
By: mirek on Fri, 18 December 2020 10:22
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Fri, 18 December 2020 08:26
|
 |
|
Re: ODBC Assertion failed
By: mr_ped on Fri, 18 December 2020 14:02
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Mon, 21 December 2020 09:54
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Tue, 22 December 2020 11:44
|
 |
|
Re: ODBC Assertion failed
By: mirek on Tue, 22 December 2020 18:22
|
 |
|
Re: ODBC Assertion failed
By: mirek on Tue, 22 December 2020 18:49
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Wed, 23 December 2020 06:08
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Wed, 27 January 2021 16:44
|
 |
|
Re: ODBC Assertion failed
By: mirek on Wed, 27 January 2021 17:08
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Thu, 28 January 2021 09:26
|
 |
|
Re: ODBC Assertion failed
By: mirek on Thu, 28 January 2021 09:38
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Fri, 12 February 2021 18:15
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Fri, 21 May 2021 11:04
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Tue, 25 May 2021 17:16
|
 |
|
Re: ODBC Assertion failed
By: mirek on Tue, 08 June 2021 10:08
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Thu, 10 June 2021 17:00
|
 |
|
Re: ODBC Assertion failed
By: JeyCi on Mon, 21 December 2020 15:33
|
 |
|
Re: ODBC Assertion failed
By: Giorgio on Mon, 24 May 2021 14:54
|
Goto Forum:
Current Time: Wed Jun 25 07:10:39 CEST 2025
Total time taken to generate the page: 0.04279 seconds
|