| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: Oracle Spatial Driver |
| 4 |
* Purpose: Test mainline for fast loading. |
| 5 |
* Author: Frank Warmerdam, [email protected] |
| 6 |
* |
| 7 |
****************************************************************************** |
| 8 |
* Copyright (c) 2002, Frank Warmerdam <[email protected]> |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: MIT |
| 11 |
****************************************************************************/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include "ogr_oci.h" |
| 15 |
|
| 16 |
int main() |
| 17 |
|
| 18 |
{ |
| 19 |
OGROCISession oSession; |
| 20 |
|
| 21 |
if (!oSession.EstablishSession("warmerda", "LetoKing", |
| 22 |
"gdal800.dreadfest.com")) |
| 23 |
{ |
| 24 |
exit(1); |
| 25 |
} |
| 26 |
|
| 27 |
printf("Session established.\n"); |
| 28 |
|
| 29 |
OGROCIStatement oStatement(&oSession); |
| 30 |
|
| 31 |
oStatement.Execute("DROP TABLE fasttest"); |
| 32 |
oStatement.Execute("CREATE TABLE fasttest (ifld INTEGER, " |
| 33 |
"cfld VARCHAR(4000), shape mdsys.sdo_geometry)"); |
| 34 |
// oStatement.Execute( "CREATE TABLE fasttest (ifld INTEGER, cfld |
| 35 |
// VARCHAR(4000))" ); |
| 36 |
|
| 37 |
/* -------------------------------------------------------------------- */ |
| 38 |
/* Prepare insert statement. */ |
| 39 |
/* -------------------------------------------------------------------- */ |
| 40 |
|
| 41 |
oStatement.Prepare("INSERT INTO fasttest VALUES " |
| 42 |
"(:field_1, :field_2, :field_3)"); |
| 43 |
// oStatement.Prepare( "INSERT INTO fasttest VALUES " |
| 44 |
// "(:field_1, :field_2)" ); |
| 45 |
|
| 46 |
/* -------------------------------------------------------------------- */ |
| 47 |
/* Do a conventional bind. */ |
| 48 |
/* -------------------------------------------------------------------- */ |
| 49 |
int anField1[100]; |
| 50 |
char szField2[100 * 4]; |
| 51 |
int anGType[100]; |
| 52 |
int anSRID[100]; |
| 53 |
OCIArray *aphElemInfos[100]; |
| 54 |
OCIArray *aphOrdinates[100]; |
| 55 |
SDO_GEOMETRY_TYPE aoGeometries[100]; |
| 56 |
SDO_GEOMETRY_ind aoGeometryIndicators[100]; |
| 57 |
SDO_GEOMETRY_TYPE *apoGeomMap[100]; |
| 58 |
SDO_GEOMETRY_ind *apoGeomIndMap[100]; |
| 59 |
// double adfX[100], adfY[100]; |
| 60 |
|
| 61 |
memset(aphElemInfos, 0, sizeof(OCIArray *) * 100); |
| 62 |
memset(aphOrdinates, 0, sizeof(OCIArray *) * 100); |
| 63 |
memset(aoGeometries, 0, sizeof(SDO_GEOMETRY) * 100); |
| 64 |
memset(aoGeometryIndicators, 0, sizeof(SDO_GEOMETRY_ind) * 100); |
| 65 |
|
| 66 |
if (oStatement.BindScalar(":field_1", anField1, sizeof(int), SQLT_INT) != |
| 67 |
CE_None) |
| 68 |
exit(1); |
| 69 |
|
| 70 |
if (oStatement.BindScalar(":field_2", szField2, 4, SQLT_STR) != CE_None) |
| 71 |
exit(1); |
| 72 |
|
| 73 |
if (oStatement.BindObject(":field_3", apoGeomMap, oSession.hGeometryTDO, |
| 74 |
(void **)apoGeomIndMap) != CE_None) |
| 75 |
exit(1); |
| 76 |
|
| 77 |
/* -------------------------------------------------------------------- */ |
| 78 |
/* Create array of arrays for elem_info and ordinates. */ |
| 79 |
/* -------------------------------------------------------------------- */ |
| 80 |
int iBindRow; |
| 81 |
for (iBindRow = 0; iBindRow < 100; iBindRow++) |
| 82 |
{ |
| 83 |
if (oSession.Failed( |
| 84 |
OCIObjectNew( |
| 85 |
oSession.hEnv, oSession.hError, oSession.hSvcCtx, |
| 86 |
OCI_TYPECODE_VARRAY, oSession.hElemInfoTDO, |
| 87 |
static_cast<dvoid *>(NULL), OCI_DURATION_SESSION, FALSE, |
| 88 |
reinterpret_cast<dvoid **>(aphElemInfos + iBindRow)), |
| 89 |
"OCIObjectNew()")) |
| 90 |
exit(1); |
| 91 |
|
| 92 |
if (oSession.Failed( |
| 93 |
OCIObjectNew( |
| 94 |
oSession.hEnv, oSession.hError, oSession.hSvcCtx, |
| 95 |
OCI_TYPECODE_VARRAY, oSession.hOrdinatesTDO, |
| 96 |
static_cast<dvoid *>(NULL), OCI_DURATION_SESSION, FALSE, |
| 97 |
reinterpret_cast<dvoid **>(aphOrdinates + iBindRow)), |
| 98 |
"OCIObjectNew()")) |
| 99 |
exit(1); |
| 100 |
} |
| 101 |
|
| 102 |
/* -------------------------------------------------------------------- */ |
| 103 |
/* Populate VARRAYs */ |
| 104 |
/* -------------------------------------------------------------------- */ |
| 105 |
int iRow; |
| 106 |
|
| 107 |
for (iRow = 0; iRow < 100; iRow++) |
| 108 |
{ |
| 109 |
// cppcheck-suppress unreadVariable |
| 110 |
anField1[iRow] = iRow; |
| 111 |
sprintf(szField2 + iRow * 4, "%3d", iRow); |
| 112 |
anGType[iRow] = 3001; |
| 113 |
anSRID[iRow] = -1; |
| 114 |
// adfX[iRow] = 100.0 + iRow; |
| 115 |
// adfY[iRow] = 100.0 - iRow; |
| 116 |
|
| 117 |
//--------------------------------------------------------------- |
| 118 |
int anElemInfo[3], nElemInfoCount; |
| 119 |
OCINumber oci_number; |
| 120 |
int i; |
| 121 |
|
| 122 |
nElemInfoCount = 3; |
| 123 |
anElemInfo[0] = 1; |
| 124 |
anElemInfo[1] = 1; |
| 125 |
anElemInfo[2] = 1; |
| 126 |
|
| 127 |
// Prepare the VARRAY of ordinate values. |
| 128 |
for (i = 0; i < nElemInfoCount; i++) |
| 129 |
{ |
| 130 |
if (oSession.Failed( |
| 131 |
OCINumberFromInt( |
| 132 |
oSession.hError, static_cast<dvoid *>(anElemInfo + i), |
| 133 |
(uword)sizeof(int), OCI_NUMBER_SIGNED, &oci_number), |
| 134 |
"OCINumberFromInt")) |
| 135 |
exit(1); |
| 136 |
|
| 137 |
if (oSession.Failed(OCICollAppend(oSession.hEnv, oSession.hError, |
| 138 |
(dvoid *)&oci_number, (dvoid *)0, |
| 139 |
aphElemInfos[iRow]), |
| 140 |
"OCICollAppend")) |
| 141 |
exit(1); |
| 142 |
} |
| 143 |
|
| 144 |
//--------------------------------------------------------------- |
| 145 |
double adfOrdinates[6]; |
| 146 |
int nOrdCount; |
| 147 |
|
| 148 |
nOrdCount = 3; |
| 149 |
adfOrdinates[0] = iRow + 100; |
| 150 |
adfOrdinates[1] = iRow - 100; |
| 151 |
adfOrdinates[2] = 0.0; |
| 152 |
adfOrdinates[3] = iRow + 100; |
| 153 |
adfOrdinates[4] = iRow - 100; |
| 154 |
adfOrdinates[5] = 0.0; |
| 155 |
|
| 156 |
// Prepare the VARRAY of ordinate values. |
| 157 |
for (i = 0; i < nOrdCount; i++) |
| 158 |
{ |
| 159 |
if (oSession.Failed( |
| 160 |
OCINumberFromReal(oSession.hError, |
| 161 |
static_cast<dvoid *>(adfOrdinates + i), |
| 162 |
(uword)sizeof(double), &oci_number), |
| 163 |
"OCINumberFromReal")) |
| 164 |
exit(1); |
| 165 |
|
| 166 |
if (oSession.Failed(OCICollAppend(oSession.hEnv, oSession.hError, |
| 167 |
static_cast<dvoid *>(&oci_number), |
| 168 |
static_cast<dvoid *>(NULL), |
| 169 |
aphOrdinates[iRow]), |
| 170 |
"OCICollAppend")) |
| 171 |
exit(1); |
| 172 |
} |
| 173 |
|
| 174 |
// ------------------------------------------------------------- |
| 175 |
SDO_GEOMETRY_TYPE *poGeom = aoGeometries + iRow; |
| 176 |
SDO_GEOMETRY_ind *poInd = aoGeometryIndicators + iRow; |
| 177 |
|
| 178 |
poInd->sdo_point._atomic = OCI_IND_NULL; |
| 179 |
|
| 180 |
if (oSession.Failed( |
| 181 |
OCINumberFromInt(oSession.hError, |
| 182 |
static_cast<dvoid *>(anGType + iRow), |
| 183 |
(uword)sizeof(int), OCI_NUMBER_SIGNED, |
| 184 |
&(poGeom->sdo_gtype)), |
| 185 |
"OCINumberFromInt")) |
| 186 |
exit(1); |
| 187 |
|
| 188 |
if (oSession.Failed( |
| 189 |
OCINumberFromInt( |
| 190 |
oSession.hError, static_cast<dvoid *>(anSRID + iRow), |
| 191 |
(uword)sizeof(int), OCI_NUMBER_SIGNED, &(poGeom->sdo_srid)), |
| 192 |
"OCINumberFromInt")) |
| 193 |
exit(1); |
| 194 |
|
| 195 |
poGeom->sdo_elem_info = aphElemInfos[iRow]; |
| 196 |
poGeom->sdo_ordinates = aphOrdinates[iRow]; |
| 197 |
|
| 198 |
apoGeomMap[iRow] = poGeom; |
| 199 |
apoGeomIndMap[iRow] = poInd; |
| 200 |
} |
| 201 |
|
| 202 |
/* -------------------------------------------------------------------- */ |
| 203 |
/* Execute the statement. */ |
| 204 |
/* -------------------------------------------------------------------- */ |
| 205 |
int iGroup; |
| 206 |
|
| 207 |
for (iGroup = 0; iGroup < 2; iGroup++) |
| 208 |
{ |
| 209 |
if (oSession.Failed( |
| 210 |
OCIStmtExecute(oSession.hSvcCtx, oStatement.GetStatement(), |
| 211 |
oSession.hError, (ub4)100, (ub4)0, |
| 212 |
(OCISnapshot *)NULL, (OCISnapshot *)NULL, |
| 213 |
(ub4)OCI_COMMIT_ON_SUCCESS), |
| 214 |
"OCIStmtExecute")) |
| 215 |
exit(1); |
| 216 |
} |
| 217 |
|
| 218 |
printf("Successful completion\n"); |
| 219 |
exit(0); |
| 220 |
} |