/ CSV Access Method opening routine. */ First allocate the Offset and Fldlen arrays according to the */ greatest field used in that query. Then call the DOS opening fnc. */ /
| 735 | /* greatest field used in that query. Then call the DOS opening fnc. */ |
| 736 | /***********************************************************************/ |
| 737 | bool TDBCSV::OpenDB(PGLOBAL g) |
| 738 | { |
| 739 | bool rc = false; |
| 740 | PCOLDEF cdp; |
| 741 | PDOSDEF tdp = (PDOSDEF)To_Def; |
| 742 | |
| 743 | if (Use != USE_OPEN && (Columns || Mode == MODE_UPDATE)) { |
| 744 | // Allocate the storage used to read (or write) records |
| 745 | int i, len; |
| 746 | PCSVCOL colp; |
| 747 | |
| 748 | if (!Fields) { // May have been set in TABFMT::OpenDB |
| 749 | if (Mode != MODE_UPDATE && Mode != MODE_INSERT) { |
| 750 | for (colp = (PCSVCOL)Columns; colp; colp = (PCSVCOL)colp->Next) |
| 751 | if (!colp->IsSpecial() && !colp->IsVirtual()) |
| 752 | Fields = MY_MAX(Fields, (int)colp->Fldnum); |
| 753 | |
| 754 | if (Columns) |
| 755 | Fields++; // Fldnum was 0 based |
| 756 | |
| 757 | } else |
| 758 | for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext()) |
| 759 | if (!cdp->IsSpecial() && !cdp->IsVirtual()) |
| 760 | Fields++; |
| 761 | } |
| 762 | |
| 763 | Offset = (int*)PlugSubAlloc(g, NULL, sizeof(int) * Fields); |
| 764 | Fldlen = (int*)PlugSubAlloc(g, NULL, sizeof(int) * Fields); |
| 765 | |
| 766 | if (Mode == MODE_INSERT || Mode == MODE_UPDATE) { |
| 767 | Field = (PSZ*)PlugSubAlloc(g, NULL, sizeof(PSZ) * Fields); |
| 768 | Fldtyp = (bool*)PlugSubAlloc(g, NULL, sizeof(bool) * Fields); |
| 769 | } // endif Mode |
| 770 | |
| 771 | for (i = 0; i < Fields; i++) { |
| 772 | Offset[i] = 0; |
| 773 | Fldlen[i] = 0; |
| 774 | |
| 775 | if (Field) { |
| 776 | Field[i] = NULL; |
| 777 | Fldtyp[i] = false; |
| 778 | } // endif Field |
| 779 | |
| 780 | } // endfor i |
| 781 | |
| 782 | if (Field) { |
| 783 | // Prepare writing fields |
| 784 | if (Mode != MODE_UPDATE) { |
| 785 | for (colp = (PCSVCOL)Columns; colp; colp = (PCSVCOL)colp->Next) |
| 786 | if (!colp->IsSpecial() && !colp->IsVirtual()) { |
| 787 | i = colp->Fldnum; |
| 788 | len = colp->GetLength(); |
| 789 | Field[i] = (PSZ)PlugSubAlloc(g, NULL, len + 1); |
| 790 | Field[i][len] = '\0'; |
| 791 | Fldlen[i] = len; |
| 792 | Fldtyp[i] = IsTypeNum(colp->GetResultType()); |
| 793 | } // endif colp |
| 794 |
no test coverage detected