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 » ArrayCtrl, HeaderCtrl & GridCtrl » [SOLVED] GridCtrl sql update
[SOLVED] GridCtrl sql update [message #33970] Sun, 02 October 2011 17:35
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I am trying to perform the updtate of a record where the fields are retrived from a GridCtrl named masterTeam. This is what I am doing with a function that performs both the update if the ID is alredy in the table and the insertion in the opposite case

void  VegaTab1::SaveMasterRecord()
{   int ndx = masterTeam.GetCurrentRow();
    if (ndx<0) return;
    int id=masterTeam(ID); // <-- make sense?
    Select(SqlAll()).From(TEAMS).Where(ID == masterTeam(ID));
	if (SQL.Fetch()) { // record already present
    	SQL.Execute("UPDATE TEAMS SET N=1, NAME='?', ORIG='?', FED='?', RTG=?, STATUS=? WHERE ID=?", 
    		masterTeam(ndx,NAME), masterTeam(ndx,ORIG), masterTeam(ndx,FED), masterTeam(ndx,RTG), masterTeam(ndx,STATUS), id);	
  	}
	else {  // new record 
		SQL.Execute("INSERT INTO TEAMS (N, NAME,ORIG,FED,RTG,STATUS) VALUES(?,?,?,?,?,?)",
			 1, masterTeam(ndx,NAME), masterTeam(ndx,ORIG), masterTeam(ndx,FED), masterTeam(ndx,RTG), masterTeam(ndx,STATUS));  		
	}
}


the table is

TABLE_(TEAMS)
INT (ID) PRIMARY_KEY AUTO_INCREMENT
INT_ (N)
STRING (NAME, 30)
STRING_ (ORIG, 30)
STRING_ (FED, 30)
INT_ (RTG)
INT_ (STATUS)
END_TABLE

Unfortunatly it performs always insertion and never the updtate.
Where is the mistake?

EDIT: this works:

void  VegaTab1::SaveMasterRecord()
{   int ndx = masterTeam.GetCurrentRow();
	if (ndx<0) return;
    int id=masterTeam(ID);
   	SQL.Execute("SELECT * FROM TEAMS WHERE ID=?", id); 
 	if (SQL.Fetch()) {
        SQL * ::Update(TEAMS) (NAME, masterTeam.Get(ndx,1))
                            (ORIG, masterTeam.Get(ndx,2))
                            (FED,  masterTeam.Get(ndx,3))
                            (RTG,  masterTeam.Get(ndx,4))
                            (STATUS, masterTeam.Get(ndx,5))
                            .Where(ID == id);
   	}
	else {
       SQL * ::Insert(TEAMS)(N, 1)
       						(NAME, masterTeam.Get(ndx,2))
                            (ORIG, masterTeam.Get(ndx,3))
                            (FED,  masterTeam.Get(ndx,4))
                            (RTG,  masterTeam.Get(ndx,5))
                            (STATUS, masterTeam.Get(ndx,6));
	}
}

[Updated on: Sun, 02 October 2011 21:30]

Report message to a moderator

Previous Topic: Export Ctrl to qtf table
Next Topic: Control Drag&drop problem
Goto Forum:
  


Current Time: Thu Mar 28 14:36:09 CET 2024

Total time taken to generate the page: 0.01059 seconds