Estoy usando Firebird con C++ 6. Tengo este código con dos TIBQuery:
Código:
Query->Close();
Query->SQL->Text = "INSERT INTO Cuentas (Padre, Cuenta, Defecto)
VALUES (:Padre, :Cuenta, :Defecto)";
qTemp->Close();
qTemp->SQL->Text = "SELECT DISTINCT A.Padre, B.Cuenta, B.Defecto
FROM ALU_TEMP A, CUE_TEMP B WHERE A.Referencia||A.Recibo = B.Referencia";
qTemp->Open();
for (; !qTemp->Eof; qTemp->Next())
{
if (!tColegio->InTransaction)
tColegio->StartTransaction();
Query->Close();
Query->ParamByName("Padre")->AsInteger = qTemp->FieldByName("Padre")->AsInteger;
Query->ParamByName("Cuenta")->AsString = qTemp->FieldByName("Cuenta")->AsString;
Query->ParamByName("Defecto")->AsInteger = qTemp->FieldByName("Defecto")->AsInteger;
try
{
Query->ExecSQL();
tColegio->Commit();
}
catch(...)
{
tColegio->Rollback();
}
}
Hace el primer insert pero cuando debería avanzar al segundo registro de lectura me dice que que no porque el dataset está cerrado (Cannot perform this operation on a closed dataset). Si fuera cierto no debría leer ni el primer registro.
He probado, en vez de un bucle, a hacer un INSERT masivo:
Código SQL
[-]INSERT INTO Cuentas (Padre, Cuenta, Defecto)
SELECT DISTINCT A.Padre, B.Cuenta, B.Defecto FROM ALU_TEMP A, CUE_TEMP B WHERE A.Referencia||A.Recibo = B.Referencia
y me da un error de violacion de claves (la tabla está indexada por padre y cuenta).
¿A alguien se le ocurre alguna idea?