/ SetBuffer: prepare a column block for write operation. */ /
| 2482 | /* SetBuffer: prepare a column block for write operation. */ |
| 2483 | /***********************************************************************/ |
| 2484 | bool DOSCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) |
| 2485 | { |
| 2486 | if (!(To_Val = value)) { |
| 2487 | snprintf(g->Message, sizeof(g->Message), MSG(VALUE_ERROR), Name); |
| 2488 | return true; |
| 2489 | } else if (Buf_Type == value->GetType()) { |
| 2490 | // Values are of the (good) column type |
| 2491 | if (Buf_Type == TYPE_DATE) { |
| 2492 | // If any of the date values is formatted |
| 2493 | // output format must be set for the receiving table |
| 2494 | if (GetDomain() || ((DTVAL *)value)->IsFormatted()) |
| 2495 | goto newval; // This will make a new value; |
| 2496 | |
| 2497 | } else if (Buf_Type == TYPE_DOUBLE) |
| 2498 | // Float values must be written with the correct (column) precision |
| 2499 | // Note: maybe this should be forced by ShowValue instead of this ? |
| 2500 | value->SetPrec(GetScale()); |
| 2501 | |
| 2502 | Value = value; // Directly access the external value |
| 2503 | } else { |
| 2504 | // Values are not of the (good) column type |
| 2505 | if (check) { |
| 2506 | snprintf(g->Message, sizeof(g->Message), MSG(TYPE_VALUE_ERR), Name, |
| 2507 | GetTypeName(Buf_Type), GetTypeName(value->GetType())); |
| 2508 | return true; |
| 2509 | } // endif check |
| 2510 | |
| 2511 | newval: |
| 2512 | if (InitValue(g)) // Allocate the matching value block |
| 2513 | return true; |
| 2514 | |
| 2515 | } // endif's Value, Buf_Type |
| 2516 | |
| 2517 | // Allocate the buffer used in WriteColumn for numeric columns |
| 2518 | if (!Buf && IsTypeNum(Buf_Type)) |
| 2519 | Buf = (char*)PlugSubAlloc(g, NULL, MY_MAX(64, Long + 1)); |
| 2520 | else // Text columns do not need additional buffer |
| 2521 | Buf = (char*)Value->GetTo_Val(); |
| 2522 | |
| 2523 | // Because Colblk's have been made from a copy of the original TDB in |
| 2524 | // case of Update, we must reset them to point to the original one. |
| 2525 | if (To_Tdb->GetOrig()) |
| 2526 | To_Tdb = (PTDB)To_Tdb->GetOrig(); |
| 2527 | |
| 2528 | // Set the Column |
| 2529 | Status = (ok) ? BUF_EMPTY : BUF_NO; |
| 2530 | return false; |
| 2531 | } // end of SetBuffer |
| 2532 | |
| 2533 | /***********************************************************************/ |
| 2534 | /* ReadColumn: what this routine does is to access the last line */ |
no test coverage detected