Skip to content

Commit

Permalink
OCI: use TIMESTAMP(3) and tweak NLS_TIME[STAMP][_TZ]_FORMAT to accept…
Browse files Browse the repository at this point in the history
… milliseconds

Fixes OSGeo#11057
  • Loading branch information
rouault committed Oct 20, 2024
1 parent dea0d97 commit e63a6e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
26 changes: 17 additions & 9 deletions autotest/ogr/ogr_oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def setup_tests():
gdaltest.oci_ds.ExecuteSQL("DELLAYER:xpoly")
gdaltest.oci_ds.ExecuteSQL("DELLAYER:testsrs")
gdaltest.oci_ds.ExecuteSQL("DELLAYER:testsrs2")
gdaltest.oci_ds.ExecuteSQL("drop table geom_test")
try:
gdaltest.oci_ds.ExecuteSQL("drop table geom_test")
except Exception:
pass
gdaltest.oci_ds.ExecuteSQL("DELLAYER:test_POINT")
gdaltest.oci_ds.ExecuteSQL("DELLAYER:test_POINT3")
gdaltest.oci_ds.ExecuteSQL("DELLAYER:test_LINESTRING")
Expand Down Expand Up @@ -730,16 +733,21 @@ def test_ogr_oci_19():
feat.SetField("MYDATE", "2015/02/03")
feat.SetField("MYDATETIME", "2015/02/03 11:33:44")
lyr.CreateFeature(feat)
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField("MYDATETIME", "2015/02/03 11:33:44.12345")
lyr.CreateFeature(feat)
lyr.SyncToDisk()

sql_lyr = gdaltest.oci_ds.ExecuteSQL("SELECT MYDATE, MYDATETIME FROM testdate")
assert sql_lyr.GetLayerDefn().GetFieldDefn(0).GetType() == ogr.OFTDate
assert sql_lyr.GetLayerDefn().GetFieldDefn(1).GetType() == ogr.OFTDateTime
f = sql_lyr.GetNextFeature()
if f.GetField(0) != "2015/02/03" or f.GetField(1) != "2015/02/03 11:33:44":
f.DumpReadable()
pytest.fail()
gdaltest.oci_ds.ReleaseResultSet(sql_lyr)
with gdaltest.oci_ds.ExecuteSQL(
"SELECT MYDATE, MYDATETIME FROM testdate"
) as sql_lyr:
assert sql_lyr.GetLayerDefn().GetFieldDefn(0).GetType() == ogr.OFTDate
assert sql_lyr.GetLayerDefn().GetFieldDefn(1).GetType() == ogr.OFTDateTime
f = sql_lyr.GetNextFeature()
assert f.GetField(0) == "2015/02/03"
assert f.GetField(1) == "2015/02/03 11:33:44"
f = sql_lyr.GetNextFeature()
assert f.GetField(1) == "2015/02/03 11:33:44.123"


###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions ogr/ogrsf_frmts/oci/ogrocisession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ int OGROCISession::EstablishSession(const char *pszUseridIn,
OGROCIStatement oSetNLSTimeFormat(this);
if (oSetNLSTimeFormat.Execute(
"ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD' \
NLS_TIME_FORMAT='HH24:MI:SS' NLS_TIME_TZ_FORMAT='HH24:MI:SS TZHTZM' \
NLS_TIMESTAMP_FORMAT='YYYY/MM/DD HH24:MI:SS' \
NLS_TIMESTAMP_TZ_FORMAT='YYYY/MM/DD HH24:MI:SS TZHTZM' \
NLS_TIME_FORMAT='HH24:MI:SS' NLS_TIME_TZ_FORMAT='HH24:MI:SS.FF TZHTZM' \
NLS_TIMESTAMP_FORMAT='YYYY/MM/DD HH24:MI:SS.FF' \
NLS_TIMESTAMP_TZ_FORMAT='YYYY/MM/DD HH24:MI:SS.FF TZHTZM' \
NLS_NUMERIC_CHARACTERS = '. '") != CE_None)
return OGRERR_FAILURE;

Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/oci/ogrociwritablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ OGRErr OGROCIWritableLayer::CreateField(const OGRFieldDefn *poFieldIn,
}
else if (oField.GetType() == OFTDateTime)
{
snprintf(szFieldType, sizeof(szFieldType), "TIMESTAMP");
snprintf(szFieldType, sizeof(szFieldType), "TIMESTAMP(3)");
}
else if (bApproxOK)
{
Expand Down

0 comments on commit e63a6e4

Please sign in to comment.