Opened 12 years ago

Closed 12 years ago

#3044 closed defect (invalid)

create index sql execute problem

Reported by: yminpark Owned by: warmerdam
Priority: normal Milestone: 1.6.2
Component: default Version: 1.6.1
Severity: normal Keywords: create, index, executeSQL



I am using GDAL 1.6.1 and I think I met a bug about sql command("create index").

I want to create attribute index on a shapefile in VS2005, so I programmed as follows :

OGRDataSource* dataSource = _dataSources[index];
OGRLayer *resultSet = NULL;
string sql;

_fileNames[index] = "LP_PA_CBND" shapefile name
_indexFields[index] = "JIBUN"
field in LP_PA_CBND.dbf

sql = "CREATE INDEX ON " + _fileNames[index] + " USING " + _indexFields[index];

resultSet = dataSource->ExecuteSQL(sql.c_str(), NULL, NULL);
if (resultSet != NULL) dataSource->ReleaseResultSet?(resultSet)

SQL seems to be executed successfully - After executing the SQL, LP_PA_CBND.ind & LP_PA_CBND.idm is created.

But OGR produced errors, too.

ERROR 3: Invalid number of indexes (0) in file C:\GMSIIS\Data\Spatial\22\LP_PA_CBND.ind
ERROR 4: Failed to open index file C:\GMSIIS\Data\Spatial\22\LP_PA_CBND.ind.

So, I tested above SQL using ogr2ogr command again. Then, no error has occurred and index file is generated in valid.

ogr2ogr -sql "create index on lp_pa_cbnd using jibun" -f "ESRI Shapefile" blahblah LP_PA_CBND.shp

I examined LP_PA_CBND.ind file with hexa viewer, then I found some difference. (please see the attached image.)

ogr2ogr : 00 02 00 00 00 1A 00 04 0F (in 000030h)
ExecuteSQL() : 00 00 00 00 00 00 00 00 00 (in 000030h)

Using sql command in ogr2ogr is different with dataSource.ExecuteSQL()?

Thank you for reading my poor english.


Attachments (1)

compare_ind.jpg (101.1 KB) - added by yminpark 12 years ago.

Download all attachments as: .zip

Change History (2)

Changed 12 years ago by yminpark

Attachment: compare_ind.jpg added

comment:1 Changed 12 years ago by Even Rouault

Resolution: invalid
Status: newclosed

I'm pretty sure you have not properly destroyed your datasource with OGRDataSource::Release().

I can reproduce the behaviour you see when I execute the following OGR Python snippet :

Console 1)
$ python
>>> import ogr
>>> ds = ogr.Open('treesa.shp')
>>> ds.ExecuteSQL( "CREATE INDEX ON treesa using id")

(the datasource is not yet closed)

Console 2)
$ ogrinfo -ro -al treesa.shp  -sql "SELECT * FROM treesa WHERE id=96"
ERROR 3: Invalid number of indexes (0) in file treesa.ind
ERROR 4: Failed to open index file treesa.ind.
INFO: Open of `../../gdal/treesa.shp'
      using driver `ESRI Shapefile' successful.

then if I close the datasource :

Console 1)
>>> ds.Destroy()

Console 2)
$ ogrinfo -ro -al treesa.shp  -sql "SELECT * FROM treesa WHERE id=96
INFO: Open of `../../gdal/treesa.shp'
      using driver `ESRI Shapefile' successful.

Layer name: treesa
Geometry: Polygon
Feature Count: 1
Extent: (-10.353545, 30.000000) - (179.999900, 71.478897)
Layer SRS WKT:
id: Integer (10.0)
f_code: String (5.0)
dmt: Integer (6.0)
exs: Integer (6.0)
nam: String (64.0)
pht: Integer (6.0)
veg: Integer (6.0)
tile_id: Integer (6.0)
fac_id: Integer (10.0)
  id (Integer) = 96
  f_code (String) = EC030
  dmt (Integer) = 0
  exs (Integer) = 0
  nam (String) = UNK
  pht (Integer) = 0
  veg (Integer) = 24
  tile_id (Integer) = 2
  fac_id (Integer) = 616
Note: See TracTickets for help on using tickets.