Browse Source

fix(api): oracledb - time value insert/update

feat/oracle-support
Pranav C 2 years ago committed by Pranav C
parent
commit
684903ddbd
  1. 4
      packages/nc-gui/components/cell/TimePicker.vue
  2. 5
      packages/nc-gui/composables/useProject.ts
  3. 16
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

4
packages/nc-gui/components/cell/TimePicker.vue

@ -11,7 +11,7 @@ const { modelValue, isPk } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject() const { isMysql, isOracle } = useProject()
const { showNull } = useGlobal() const { showNull } = useGlobal()
@ -25,7 +25,7 @@ const column = inject(ColumnInj)!
let isTimeInvalid = $ref(false) let isTimeInvalid = $ref(false)
const dateFormat = isMysql(column.value.base_id) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ' const dateFormat = isMysql(column.value.base_id) || isOracle(column.value.base_id) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ'
const localState = $computed({ const localState = $computed({
get() { get() {

5
packages/nc-gui/composables/useProject.ts

@ -82,6 +82,10 @@ export const useProject = createSharedComposable(() => {
return ['mysql', ClientType.MYSQL].includes(getBaseType(baseId)) return ['mysql', ClientType.MYSQL].includes(getBaseType(baseId))
} }
function isOracle(baseId?: string) {
return getBaseType(baseId) === 'oracledb'
}
function isMssql(baseId?: string) { function isMssql(baseId?: string) {
return getBaseType(baseId) === 'mssql' return getBaseType(baseId) === 'mssql'
} }
@ -204,6 +208,7 @@ export const useProject = createSharedComposable(() => {
loadTables, loadTables,
isMysql, isMysql,
isMssql, isMssql,
isOracle,
isPg, isPg,
sqlUis, sqlUis,
isSharedBase, isSharedBase,

16
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1644,18 +1644,16 @@ class BaseModelSqlv2 {
if (this.isOracle) { if (this.isOracle) {
for (const col of this.model.columns) { for (const col of this.model.columns) {
if ( if (
(col.dt === 'DATE' || col.dt.startsWith('TIMESTAMP')) && !insertObj[col.column_name] ||
col.uidt === UITypes.Date && !(col.dt === 'DATE' || col.dt.startsWith('TIMESTAMP'))
insertObj[col.column_name] )
) { continue;
if (col.uidt === UITypes.Date) {
insertObj[col.column_name] = this.dbDriver.raw( insertObj[col.column_name] = this.dbDriver.raw(
`TO_DATE('${insertObj[col.column_name]}','YYYY-MM-DD')` `TO_DATE('${insertObj[col.column_name]}','YYYY-MM-DD')`
); );
} else if ( } else if (col.uidt === UITypes.DateTime || col.uidt === UITypes.Time) {
(col.dt === 'DATE' || col.dt.startsWith('TIMESTAMP')) &&
col.uidt === UITypes.DateTime &&
insertObj[col.column_name]
) {
// ref - https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924 // ref - https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
insertObj[col.column_name] = this.dbDriver.raw( insertObj[col.column_name] = this.dbDriver.raw(
`TO_DATE('${insertObj[col.column_name]}','yyyy-MM-dd HH24:mi:ss')` `TO_DATE('${insertObj[col.column_name]}','yyyy-MM-dd HH24:mi:ss')`

Loading…
Cancel
Save