/ BSONColumns: construct the result blocks containing the description */ of all the columns of a table contained inside a JSON file. */ /
| 61 | /* of all the columns of a table contained inside a JSON file. */ |
| 62 | /***********************************************************************/ |
| 63 | PQRYRES BSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) |
| 64 | { |
| 65 | static int buftyp[] = { TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, |
| 66 | TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING }; |
| 67 | static XFLD fldtyp[] = { FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, |
| 68 | FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT }; |
| 69 | static unsigned int length[] = { 0, 6, 8, 10, 10, 6, 6, 0 }; |
| 70 | int i, n = 0; |
| 71 | int ncol = sizeof(buftyp) / sizeof(int); |
| 72 | PJCL jcp; |
| 73 | BSONDISC* pjdc = NULL; |
| 74 | PQRYRES qrp; |
| 75 | PCOLRES crp; |
| 76 | |
| 77 | if (info) { |
| 78 | length[0] = 128; |
| 79 | length[7] = 256; |
| 80 | goto skipit; |
| 81 | } // endif info |
| 82 | |
| 83 | if (GetIntegerTableOption(g, topt, "Multiple", 0)) { |
| 84 | safe_strcpy(g->Message, sizeof(g->Message), "Cannot find column definition for multiple table"); |
| 85 | return NULL; |
| 86 | } // endif Multiple |
| 87 | |
| 88 | pjdc = new(g) BSONDISC(g, length); |
| 89 | |
| 90 | if (!(n = pjdc->GetColumns(g, db, dsn, topt))) |
| 91 | return NULL; |
| 92 | |
| 93 | skipit: |
| 94 | if (trace(1)) |
| 95 | htrc("BSONColumns: n=%d len=%d\n", n, length[0]); |
| 96 | |
| 97 | /*********************************************************************/ |
| 98 | /* Allocate the structures used to refer to the result set. */ |
| 99 | /*********************************************************************/ |
| 100 | qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, |
| 101 | buftyp, fldtyp, length, false, false); |
| 102 | |
| 103 | crp = qrp->Colresp->Next->Next->Next->Next->Next->Next; |
| 104 | crp->Name = PlugDup(g, "Nullable"); |
| 105 | crp->Next->Name = PlugDup(g, "Jpath"); |
| 106 | |
| 107 | if (info || !qrp) |
| 108 | return qrp; |
| 109 | |
| 110 | qrp->Nblin = n; |
| 111 | |
| 112 | /*********************************************************************/ |
| 113 | /* Now get the results into blocks. */ |
| 114 | /*********************************************************************/ |
| 115 | for (i = 0, jcp = pjdc->fjcp; jcp; i++, jcp = jcp->Next) { |
| 116 | if (jcp->Type == TYPE_UNKNOWN) |
| 117 | jcp->Type = TYPE_STRG; // Void column |
| 118 | |
| 119 | crp = qrp->Colresp; // Column Name |
| 120 | crp->Kdata->SetValue(jcp->Name, i); |
no test coverage detected