ADO multi-table update BCB implementation

zhaozj2021-02-16  77

Thanks strong thanks to PPOWER.ado multi-table update code, Welcome refers to Xuchaofei@jit.com.tw, ​​// --------------------------------------------------------------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------ Define a structure in .h file: struct fieldValue {Ansistring fnname; variant fnvalue;}; struct fieldinfor {std :: vector myvalue;}; //// ---------- On the private section: std :: Vector myfieldinfor; std :: vector Tablefield; void __fastcall gettheupdatetable (std :: vector & tablename) ; Void __fastcall beforepostev (TDataSet * Dataset); // ----------------------- in the CPP file: in order to order multi-table SQL statements DataSet's BeforePost event is added as follows: BeForePostev (DataSet); // ----------------------- void __fastcall tmutableop :: beforePostev (TDataSet * Dataset) {IF (DataSet-> Modified) {FieldInfor Tempvector; for (int i = 0; i fieldcount; i) {FieldValue Allfield; allfield.fname = DataSet-> Fields-> Fields [i] -> FieldName; allfield.fnvalue = dataset-> fields-> fields [i] -> value; TempVector.MyValue.push_back (allfield); // Save all the contents of the data of the field with the data changed. } Myfieldinfor.push_back (tempvector);}} // ------------------------------- // Hypothesis has obtained After changing the field, then compare it, see the data of that table, and update.

void __fastcall TMutableOp :: GetTheUpdateTable (std :: vector & TableName) {std :: auto_ptr Query (new TADOQuery (NULL)); Query-> Connection = ADOConnection1; // -------- -------------------------------------------------- --- for (std :: size_t i = 0; i

Tempa.delete (1, Tablename [T] .length ()); // remove the table name to Tempa.Delete (1, 5); // Remove _Key to get true field name FieldValue Fieldstruct;

KeyFieldID = TempA; KeyFieldValue = MyFieldInfor [i] .MyValue [j] .FNValue; FieldStruct.FNName = TempA; FieldStruct.FNValue = MyFieldInfor [i] .MyValue [j] .FNValue; TableField.push_back (FieldStruct);} else { FieldValue Fieldstruct; Ansistring Tempa = MyfieldInfor [i] .myvalue [J] .fname ;; Tempa.delete (1, Tablename [T). Dengthth ()); // remove the table name to Tempa.delete (1, 2); // put __ remove

Fieldstruct.fname = Tempa; FieldStruct.fnValue = myfieldinfor [i] .myvalue [j] .fnvalue; Tablefield.push_back (fieldstructure);}

} Else {// If the table name is different, do not do}}} // 3 for // The data of the first table is found, and the synthetic IF of the update SQL statement is made here. Size () == 0) Return; ANSISTRING SQL; SQL = "SELECT"; for (std :: size_t v = 0; V

I can only use the SQL statement to add the corresponding identification information: SELECT A.ID AA_KEY_ID, A.NAME AA__NAME, A.STDNO AA__STDNO, B.MARK AS BB__MARK, B.ID AS BB_KEY_ID from AA As A , Bb as b where a.stdno = b.stdno // -------- AA, BB is a table name: The configuation field of each table is given: I use "Table Name _Key Contempted Field Name "to indicate that the name of each field is used:" Table Name __ field name "above SQL statement, if not add information: SQL is like this: SELECT A. ID, A.Name, A.stdno, B.mark, B.ID from AA AA, BB AS B So some of the SQL statements, this is only multi-table modified, deleted, and new code in understanding some code Write on the basis. The principle of implementation is: Record each change over the record and then take this record to classify. Take it to compare it with the database original data, if it is not the same, change it.

转载请注明原文地址:https://www.9cbs.com/read-15247.html

New Post(0)