CAMLprim value mapi_error_str_stub(value conn) { char *error_str = mapi_error_str((Mapi) conn); if (error_str) { return caml_copy_string(error_str); } else { return caml_copy_string(""); } }
SQLRETURN MNDBFetch(ODBCStmt *stmt, SQLUSMALLINT *RowStatusArray) { ODBCDesc *ard, *ird; ODBCDescRec *rec; int i; SQLULEN row; SQLLEN offset; /* stmt->startRow is the (0 based) index of the first row we * stmt->need to fetch */ ard = stmt->ApplRowDescr; ird = stmt->ImplRowDescr; stmt->retrieved = 0; stmt->currentCol = 0; stmt->rowSetSize = 0; stmt->currentRow = stmt->startRow + 1; if (mapi_seek_row(stmt->hdl, stmt->startRow, MAPI_SEEK_SET) != MOK) { /* Row value out of range */ addStmtError(stmt, "HY107", mapi_error_str(stmt->Dbc->mid), 0); return SQL_ERROR; } stmt->State = FETCHED; if (stmt->retrieveData == SQL_RD_OFF) { /* don't really retrieve the data, just do as if, updating the SQL_DESC_ARRAY_STATUS_PTR */ stmt->rowSetSize = ard->sql_desc_array_size; if (stmt->startRow + stmt->rowSetSize > (SQLLEN) stmt->rowcount) stmt->rowSetSize = stmt->rowcount - stmt->startRow; if (stmt->rowSetSize <= 0) { stmt->rowSetSize = 0; return SQL_NO_DATA; } if (RowStatusArray) { for (row = 0; (SQLLEN) row < stmt->rowSetSize; row++) { WriteValue(RowStatusArray, SQL_ROW_SUCCESS); RowStatusArray++; } for (; row < ard->sql_desc_array_size; row++) { WriteValue(RowStatusArray, SQL_ROW_NOROW); RowStatusArray++; } } return SQL_SUCCESS; } if (ard->sql_desc_bind_offset_ptr) offset = *ard->sql_desc_bind_offset_ptr; else offset = 0; for (row = 0; row < ard->sql_desc_array_size; row++) { if (mapi_fetch_row(stmt->hdl) == 0) { switch (mapi_error(stmt->Dbc->mid)) { case MOK: if (row == 0) return SQL_NO_DATA; break; case MTIMEOUT: if (RowStatusArray) WriteValue(RowStatusArray, SQL_ROW_ERROR); /* Timeout expired / Communication * link failure */ addStmtError(stmt, stmt->Dbc->sql_attr_connection_timeout ? "HYT00" : "08S01", mapi_error_str(stmt->Dbc->mid), 0); return SQL_ERROR; default: if (RowStatusArray) WriteValue(RowStatusArray, SQL_ROW_ERROR); /* General error */ addStmtError(stmt, "HY000", mapi_error_str(stmt->Dbc->mid), 0); return SQL_ERROR; } break; } if (RowStatusArray) WriteValue(RowStatusArray, SQL_ROW_SUCCESS); stmt->rowSetSize++; for (i = 1; i <= ird->sql_desc_count; i++) ird->descRec[i].already_returned = 0; for (i = 1; i <= ard->sql_desc_count; i++) { rec = &ard->descRec[i]; if (rec->sql_desc_data_ptr == NULL) continue; stmt->retrieved = 0; if (ODBCFetch(stmt, i, rec->sql_desc_concise_type, rec->sql_desc_data_ptr, rec->sql_desc_octet_length, rec->sql_desc_octet_length_ptr, rec->sql_desc_indicator_ptr, rec->sql_desc_precision, rec->sql_desc_scale, rec->sql_desc_datetime_interval_precision, offset, row) == SQL_ERROR) { if (RowStatusArray) WriteValue(RowStatusArray, SQL_ROW_SUCCESS_WITH_INFO); } } if (RowStatusArray) RowStatusArray++; } if (ird->sql_desc_rows_processed_ptr) *ird->sql_desc_rows_processed_ptr = (SQLULEN) stmt->rowSetSize; if (RowStatusArray) while (row++ < ard->sql_desc_array_size) { WriteValue(RowStatusArray, SQL_ROW_NOROW); RowStatusArray++; } return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS; }