Click here to Skip to main content
15,899,634 members
Home / Discussions / Database
   

Database

 
Questionsql syntax Pin
Arif Liminto27-Nov-06 15:53
professionalArif Liminto27-Nov-06 15:53 
AnswerRe: sql syntax Pin
Coding C#27-Nov-06 19:24
Coding C#27-Nov-06 19:24 
GeneralRe: sql syntax Pin
Arif Liminto27-Nov-06 20:26
professionalArif Liminto27-Nov-06 20:26 
GeneralRe: sql syntax Pin
asithangae27-Nov-06 21:20
asithangae27-Nov-06 21:20 
GeneralRe: sql syntax Pin
Colin Angus Mackay27-Nov-06 22:30
Colin Angus Mackay27-Nov-06 22:30 
GeneralRe: sql syntax Pin
Coding C#28-Nov-06 0:21
Coding C#28-Nov-06 0:21 
GeneralRe: sql syntax Pin
Paul Conrad28-Nov-06 13:40
professionalPaul Conrad28-Nov-06 13:40 
QuestionPostgreSQL, ODBC and transaction strange behavior Pin
Le Sourcier27-Nov-06 3:55
Le Sourcier27-Nov-06 3:55 
I've a serious problem Cry | :(( in my software while inserting data in PostgreSQL tables.

I'm using VC6.0 sp6, the last PostgresSQL release and the last associated psqlODBC driver.

I can not find anything in msdn help, so I post my problem and I except that someone could help me.Roll eyes | :rolleyes:

That is the way I insert my data:

1. I create a database connection to my database, using psqlODBC driver
2. I open a recordset (with appendOnly and bulkrowadd options)
3. Start a transaction with CDatabase::BeginTrans()
3. I insert lots new records to my table (hundreds of records)
4. Commit transaction with CDatabase::CommitTrans();
5. Close database connection

But, when an insert fails (a CDBExcpetion is thrown in Update() function), then all previously non commited records are lost !!!Unsure | :~
I just want only bad insert to be lost but not all my records updated since BeginTrans()

Here is my code :

CDatabase * pDatabase = new CDatabase();<br />
pDatabase->OpenEx(); //ask user to select a DSN<br />
<br />
CRecordsetST myRecordset(pDatabase);<br />
myRecordset.Open(AFX_DB_USE_DEFAULT_TYPE, NULL, CRecordset::optimizeBulkAdd | CRecordset::appendOnly);<br />
if(!myRecordset.IsOpen())<br />
{<br />
	pDatabase->Close();<br />
	return;<br />
}<br />
<br />
pDatabase->BeginTrans();<br />
<br />
while( //file is not EOF )<br />
{<br />
	try<br />
	{<br />
		myRecordset.AddNew();<br />
		//fill recordset fields with file data<br />
		//.....<br />
		//.....<br />
		//.....<br />
		//.....<br />
		myRecordset.Update();<br />
	}<br />
	catch(CDBException *e)<br />
	{<br />
		//if a CDBException is catched, then<br />
		//cancelupdate to pass current record<br />
		//and continue to next data without<br />
		//doing rollback<br />
<br />
		//cancel update to prepare next record<br />
		myRecordset.CancelUpdate();<br />
		//trace some message<br />
		OutputDebugString(e->m_strError+_T("\n"));<br />
		e->Delete();<br />
<br />
		//here I do not want to rollback my transaction, but just cancel current update<br />
		//and continue my process with keeping all previously added records (good ones)<br />
	}<br />
	catch(...)<br />
    	{<br />
		//if an unknown exception if catched then rollback all<br />
		myRecordset.CancelUpdate();<br />
		//trace some message<br />
		OutputDebugString(_T("FATAL error while inserting data\n"));<br />
		//perform rollback<br />
		pDatabase->Rollback();<br />
		pDatabase->Close();<br />
		return;<br />
    	}<br />
	//read next line in file<br />
}<br />
<br />
pDatabase->CommitTrans();<br />
pDatabase->Close();<br />
...



I've tried to commit current transaction in first catch, but records are not saved.
I've searched for some options in CDatabase or CRecordset, but I didn't find anything.


I excepect that you could help me.
thanks for all.

Le Sourcier

QuestionSQL Query - join or exists? Pin
Dewald27-Nov-06 3:26
Dewald27-Nov-06 3:26 
AnswerRe: SQL Query - join or exists? Pin
ednrgc27-Nov-06 3:33
ednrgc27-Nov-06 3:33 
GeneralRe: SQL Query - join or exists? Pin
Dewald27-Nov-06 4:05
Dewald27-Nov-06 4:05 
GeneralRe: SQL Query - join or exists? Pin
ednrgc27-Nov-06 4:08
ednrgc27-Nov-06 4:08 
GeneralRe: SQL Query - join or exists? Pin
Dewald27-Nov-06 4:21
Dewald27-Nov-06 4:21 
GeneralRe: SQL Query - join or exists? Pin
ednrgc27-Nov-06 9:15
ednrgc27-Nov-06 9:15 
AnswerRe: SQL Query - join or exists? Pin
Pete O'Hanlon27-Nov-06 9:16
mvePete O'Hanlon27-Nov-06 9:16 
AnswerRe: SQL Query - join or exists? Pin
Michael Potter27-Nov-06 10:16
Michael Potter27-Nov-06 10:16 
QuestionSQL help needed Pin
jegastar27-Nov-06 2:06
jegastar27-Nov-06 2:06 
AnswerRe: SQL help needed Pin
Pete O'Hanlon27-Nov-06 2:15
mvePete O'Hanlon27-Nov-06 2:15 
AnswerRe: SQL help needed Pin
jegastar27-Nov-06 2:28
jegastar27-Nov-06 2:28 
GeneralRe: SQL help needed Pin
jegastar27-Nov-06 2:30
jegastar27-Nov-06 2:30 
GeneralRe: SQL help needed Pin
Rob Graham27-Nov-06 2:55
Rob Graham27-Nov-06 2:55 
Question"trigger" Pin
ravikiranreddydharmannagari26-Nov-06 20:16
ravikiranreddydharmannagari26-Nov-06 20:16 
AnswerRe: "trigger" Pin
Pete O'Hanlon27-Nov-06 1:41
mvePete O'Hanlon27-Nov-06 1:41 
AnswerRe: "trigger" Pin
Eric Dahlvang27-Nov-06 3:23
Eric Dahlvang27-Nov-06 3:23 
QuestionConnecting Problem [modified] Pin
firebow300726-Nov-06 19:40
firebow300726-Nov-06 19:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.