Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » SqlMassinsert
SqlMassinsert [message #34193] Mon, 31 October 2011 11:07 Go to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hello everybody,

I want to do mass insertion using SqlExp and do not know how to do.
i mean i want

begin transaction
for(...)
insert something
end transaction

Thank you for your reply.



Re: SqlMassinsert [message #34269 is a reply to message #34193] Mon, 07 November 2011 14:14 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Here is the code snippet that uses MassInsert to copy Dbf database into SQL database:

DbfStream dbf;
if(!dbf.Open(file))
	return false;
SqlMassInsert ins(table);
while(dbf.Fetch())
	if(!IsNull(dbf[c[0]])) {
		for(int i = 0; i < c.GetCount(); i++)
			ins(SqlId(c[i]), dbf[c[i]]);
			ins.EndRow();
			if(SQL.WasError()) {
				ProgressEnd();
				return false;
			}
		}
	}
ins.Flush();


SqlMassInsert uses "insert into ... select ... union all ... select" trick to combine many inserts into single SQL statement; this speeds up things as there can be only single locking / index redoing for the whole statement... (Note that it has special complex logic for NULL values that otherwise pose a problem in this strategy).

Mirek

[Updated on: Mon, 07 November 2011 14:15]

Report message to a moderator

Previous Topic: console + sql + unicode or utf
Next Topic: Error when compiling native MySql with MSC9
Goto Forum:
  


Current Time: Wed Apr 17 00:48:07 CEST 2024

Total time taken to generate the page: 0.02635 seconds