Ns_PdDbGetRow

Name

Ns_PdDbGetRow -- Send to client a row associated with the column count.

Syntax

void Ns_PdDbGetRow (void *handle, char *columnCount);

Description

This function should retrieve from the DBMS the row associated with the columnCount column and send this data to the client. For example:

if (status == DB_END_DATA) {
  Ns_PdSendData(END_DATA, strlen(END_DATA));
} else {
  Ns_PdSendRowInfo(rowInfo);
}

If the get-row operation was successful, this function should call Ns_PdSendString with an OK_STATUS and then send the data with Ns_PdDbSendData. On failure, the function should use Ns_PdSendString to return an error.

Pseudo-code Example

/* DBMSState, DBMSGetRow are your DBMS-specific structures and calls. */

void
Ns_PdDbGetRow(void *handle, char *columnCount) {
  DBMSState *state = (DBMSState *) handle;
  Ns_PdRowInfo *rowInfo;
  int ncols;
  Ns_PdLog(Trace, "getrow(%s):", columnCount);
  ncols = atoi(columnCount);
  if ((rowInfo = Ns_PdNewRowInfo(ncols)) == NULL) {
    char errbuf[ERRBUF_SIZE];
    sprintf(errbuf, "DBMS proxy daemon could not allocate memory for row(%d)", ncols);
    Ns_PdSendString(errbuf);
  } else {
    int status;
    Ns_PdSetRowInfoNumColumns(rowInfo, ncols);
    if ((status = DBMSGetRow(state, rowInfo)) == NS_ERROR) {
      Ns_PdSendException(state->exceptionCode, state->exceptionMsg);
    } else {
      Ns_PdSendString(OK_STATUS);
      if (status == DB_END_DATA) {
        Ns_PdSendData(END_DATA, strlen(END_DATA));
      } else {
        Ns_PdSendRowInfo(rowInfo);
      }
    }
    Ns_PdFreeRowInfo(rowInfo, 0);
  }
}