$operations[$index] = $operation; } $response = null; try { $data = $datasource->executeTransactOperations($operations); $response = Response::makeCustomResponse($datasource->getResponseCode(), $datasource->getDBMessage(), $data, null); } catch (Exception $ex) { $response = Response::makeCustomResponse($datasource->getResponseCode(), $datasource->getDBMessage(), false, $datasource->getException()); } $datasource->closeDB(); echo json_encode($response); } else { // // Not in a transaction // $operation = MySQLOperation::createOperation($operationArray); $response = null; try { $data = $datasource->executeOperation($operation); $response = Response::makeCustomResponse($datasource->getResponseCode(), $datasource->getDBMessage(), $data, $datasource->getException()); } catch (Exception $ex) { $response = Response::makeCustomResponse($datasource->getResponseCode(), $datasource->getDBMessage(), $data, $datasource->getException()); } $datasource->closeDB(); echo json_encode($response); } } else { // // Database not open // $response->makeCustomResponse(-1, "Database is closed", null, $datasource->getException());
public static function createOperation($operationArray) { $op = $operationArray['operation']; $operation = new MySQLOperation($op); $operation->setTable($operationArray['table']); if (isset($operationArray['projection'])) { $operation->setProjection($operationArray['projection']); } if (isset($operationArray['where'])) { $operation->setWhere($operationArray['where']); } if (isset($operationArray['whereArgs'])) { $operation->setWhereArgs($operationArray['whereArgs']); } if (isset($operationArray['groupBy'])) { $operation->setGroupBy($operationArray['groupBy']); } if (isset($operationArray['having'])) { $operation->setHaving($operationArray['having']); } if (isset($operationArray['orderBy'])) { $operation->setOrderBy($operationArray['orderBy']); } if (isset($operationArray['limit'])) { $operation->setLimit($operationArray['limit']); } if (isset($operationArray['values'])) { $operation->setValues($operationArray['values']); } if (isset($operationArray['statement'])) { $operation->setStatement($operationArray['statement']); } if (isset($operationArray['bindValues'])) { $operation->setBindValues($operationArray['bindValues']); } if (isset($operationArray['returnId'])) { $operation->setReturnId($operationArray['returnId']); } return $operation; }