query($sql); $exist = TRUE; if ($result == NULL) { // no result ... $exist = FALSE; } //echo("find result : ".$result); if ($result->num_rows > 0) { $userGroup = $result->fetch_assoc(); $idGroup = $userGroup['id']; } else { $exist = FALSE; } if ($exist == FALSE) { // create a new one ... $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" ." VALUES ('".$userName."'," ." '".$libName."'," ." '".$_POST['LIB_BRANCH']."')"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { $exist == TRUE; $idGroup = $COVERAGE_bdd->insert_id; } else { echo "[ERROR] Can not CREATE new group ..."; } } if ($idGroup <= -1) { echo("[ERROR] can not create or find group"); } else { $sql = " INSERT INTO `BUILD_list` (`time`, `id-group`, `sha1`, `tag`, `status`)" ." VALUES ('".time()."'," ." '".$idGroup."'," ." '".$_POST['SHA1']."'," ." '".$_POST['TAG']."'," ." '".$_POST['STATUS']."')"; //echo $sql; $result = $COVERAGE_bdd->query($sql); if ($result == FALSE) { echo("[ERROR] Can not register in db ... (LIST)"); } $sql = "SELECT `BUILD_snapshot`.`id` " ." FROM `BUILD_snapshot`" ." , `CI_group`" ." WHERE `CI_group`.`user-name` = '".$userName."'" ." AND `CI_group`.`lib-name` = '".$libName."'" ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" ." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`" ." LIMIT 1"; $result = $COVERAGE_bdd->query($sql); //echo("sql : ".$sql); if ( $result == NULL || $result->num_rows == 0) { // simply insert: $sql = " INSERT INTO `BUILD_snapshot` (`id-group`, `".$_POST['TAG']."`)" ." VALUES ('".$idGroup."'," ." '".$_POST['STATUS']."')"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { echo("[OK] registered done (new entry)"); } else { echo("[ERROR] Can not register in db ... (snapshot)"); } } else { // try to update the curent values: $sql = " UPDATE `BUILD_snapshot`" ." SET `BUILD_snapshot`.`".$_POST['TAG']."` = '".$_POST['STATUS']."'" ." WHERE `BUILD_snapshot`.`id-group` = '".$idGroup."'"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { echo("[OK] registered done (update)"); } else { echo("[ERROR] Can not register in db ... (snapshot)"); } } } // simply close link with the DB... $COVERAGE_bdd->close(); ?>