Skip to content

Improve Oracle DATE/TIMESTAMP handling#57

Merged
hymkor merged 5 commits into
masterfrom
push-kmzvtxqkkqtu
May 12, 2026
Merged

Improve Oracle DATE/TIMESTAMP handling#57
hymkor merged 5 commits into
masterfrom
push-kmzvtxqkkqtu

Conversation

@hymkor
Copy link
Copy Markdown
Owner

@hymkor hymkor commented May 12, 2026

Summary

This PR improves Oracle DATE/TIMESTAMP handling and avoids timezone-dependent behavior caused by differences in Oracle driver implementations.

Instead of relying on Go time.Time timezone handling, Oracle datetime values are now converted through database-specific string formatting and SQL-side TO_DATE / TO_TIMESTAMP conversion.

Changes

  • Add FormatValue hook to dialect.Entry
    • allows database-specific string formatting for displayed values
  • Improve conversion hooks in rowstocsv
    • refine hook timing and parameters for database-to-CSV conversion
  • Apply dialect-specific formatting in spread
    • select and edit now use database-specific cell formatting
  • Add Oracle-specific datetime formatting
    • DATE values are formatted as:
      • 2006-01-02 15:04:05
    • TIMESTAMP values are formatted as:
      • 2006-01-02 15:04:05.999999999
  • Use TO_DATE / TO_TIMESTAMP for Oracle datetime comparisons and updates
  • Update Oracle tests
    • timezone strings are no longer expected in Oracle datetime output

Notes

Oracle DATE and TIMESTAMP columns do not contain timezone information, but different versions of go-ora attach different timezone metadata to Go time.Time values.

This PR avoids relying on timezone behavior and instead uses timezone-independent string representations for Oracle datetime handling.

Unlike [#49](#49), this approach should theoretically work with both go-ora v2.8.x and v2.9.x.


go-ora ドライバーって、2.8 だと time.Time に入ってくるタイムゾーンが time.Local になるのに、2.9 だと UTC になってしまいます。で、それだとレコードの照合がうまくいかなくなるのが困るので、#55 では、日時の照合と日時の名前の値ではなく、TO_DATE , TO_TIMESTAMP を経由使って行うようにしました。
その結果として、edit コマンドや select コマンドで出てくるタイムゾーン情報(例:+09:00)は無意味になってしまいました(ユーザが編集しても使わない)。ならばそもそも表示しないようにしようというのが本修正です。

ただし、Oracle 向けの特別扱いはよくないため、本修正では、各DBごとに SELECT/EDIT 文で出す表現情報をカスタマイズできるような仕組みを作ってから、それを使いました。今後、他の DB 向けにもこの仕組みを使うと思います。
(dialent サブパッケージの Entry 構造体の FormatValue フィールドに格納されている関数に型名と値を渡せば、その DB 固有の表現が得られるという仕組み。ただし、フィールドが空の場合や、第二戻り値が false の場合は固有のカスタマイズはないと解釈しなければいけない)

@hymkor hymkor self-assigned this May 12, 2026
@hymkor hymkor merged commit 5f47989 into master May 12, 2026
2 checks passed
@hymkor hymkor deleted the push-kmzvtxqkkqtu branch May 12, 2026 09:23
hymkor added a commit that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant