private function exportar_tablas_nucleo_multiproyecto(toba_modelo_instancia $instancia) { $this->manejador_interface->titulo("Tablas NUCLEO - PROYECTO"); foreach (toba_db_tablas_nucleo::get_lista_nucleo_multiproyecto() as $tabla) { $definicion = toba_db_tablas_nucleo::$tabla(); //Genero el SQL if (isset($definicion['dump_where']) && trim($definicion['dump_where']) != '') { $w = stripslashes($definicion['dump_where']); $where = str_replace("%%", 'toba', $w); } else { $where = " ( proyecto = 'toba')"; } $sql = 'SELECT ' . implode(', ', $definicion['columnas']) . " FROM {$tabla} " . " WHERE {$where} " . " ORDER BY {$definicion['dump_order_by']} ;\n"; //$this->manejador_interface->mensaje( $sql ); $contenido = ""; $datos = $instancia->get_db()->consultar($sql); $regs = count($datos); if ($regs > 1) { $columnas_orden = array_map('trim', explode(',', $definicion['dump_order_by'])); $datos = rs_ordenar_por_columnas($datos, $columnas_orden); } $this->manejador_interface->mensaje("TABLA {$tabla} -- {$regs}"); for ($a = 0; $a < $regs; $a++) { $contenido .= sql_array_a_insert($tabla, $datos[$a], $instancia->get_db()) . "\n"; } if (trim($contenido) != '') { $this->guardar_tabla_archivo($tabla, $contenido); } } }
private function exportar_tablas_proyecto($metodo_lista_tablas, $nombre_archivo, $proyecto, $texto) { $append = false; foreach (toba_db_tablas_instancia::$metodo_lista_tablas() as $tabla) { $definicion = toba_db_tablas_instancia::$tabla(); //Genero el SQL if (isset($definicion['dump_where']) && trim($definicion['dump_where']) != '') { $w = stripslashes($definicion['dump_where']); $where = str_replace("%%", $proyecto, $w); } else { $where = " ( proyecto = '{$proyecto}')"; } $from = "{$tabla} dd"; if (isset($definicion['dump_from']) && trim($definicion['dump_from']) != '') { $from .= ", " . stripslashes($definicion['dump_from']); } $columnas = array(); foreach ($definicion['columnas'] as $columna) { $columnas[] = "dd.{$columna}"; } $sql = 'SELECT ' . implode(', ', $columnas) . " FROM {$from} " . " WHERE {$where} " . " ORDER BY {$definicion['dump_order_by']} ;\n"; $sentencia = $this->get_db()->get_pdo()->query($sql); while ($fila = $sentencia->fetch(PDO::FETCH_ASSOC)) { $contenido = sql_array_a_insert($tabla, $fila, $this->get_db()) . "\n"; $this->guardar_archivo($nombre_archivo, $contenido, $append); $append = true; } $this->manejador_interface->progreso_avanzar(); } }
/** * Dada la información contenida en el xml intenta insertar los datos en una base * En caso de falla, se sigue adelante en la transacción utilizando SAVEPOINTs (postgres>=8.0) */ function insertar_db($conexion, $path_proyecto = null) { $conexion->retrazar_constraints(false); $tablas = $this->get_tablas(); $errores = array(); $i = 0; $sql = ''; //-- Recorre cada tabla foreach ($tablas as $tabla => $filas) { //-- Recorre cada fila foreach ($filas as $fila) { try { //Guarda un savepoint por si falla la ejecucion $conexion->ejecutar('SAVEPOINT toba_' . $i); $sql = sql_array_a_insert($tabla, $fila, $conexion); $conexion->ejecutar($sql); //Si no falla se libera el savepoint $conexion->ejecutar('RELEASE SAVEPOINT toba_' . $i); } catch (Exception $e) { //Al fallar se vuelve al estado anterior del fallo $conexion->ejecutar('ROLLBACK TO SAVEPOINT toba_' . $i); $errores[] = array('tabla' => $tabla, 'sql' => $sql, 'datos' => $fila, 'msg_motor' => $e->getMessage(), 'extras' => null); } $i++; } } $conexion->retrazar_constraints(true); return $errores; }