<commit_before>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by The MIT License
// found in the accompanying LICENSE file.

package ora

/*
#include <oci.h>
#include "version.h"
*/
import "C"
import (
	"bytes"
	"math"
	"strings"
	"time"
	"unsafe"
)

type defTime struct {
	rset        *Rset
	ocidef      *C.OCIDefine
	ociDateTime *C.OCIDateTime
	null        C.sb2
	isNullable  bool
}

func (def *defTime) define(position int, isNullable bool, rset *Rset) error {
	def.rset = rset
	def.isNullable = isNullable
	r := C.OCIDEFINEBYPOS(
		def.rset.ocistmt,                              //OCIStmt     *stmtp,
		&def.ocidef,                                   //OCIDefine   **defnpp,
		def.rset.stmt.ses.srv.env.ocierr,              //OCIError    *errhp,
		C.ub4(position),                               //ub4         position,
		unsafe.Pointer(&def.ociDateTime),              //void        *valuep,
		C.LENGTH_TYPE(unsafe.Sizeof(def.ociDateTime)), //sb8         value_sz,
		C.SQLT_TIMESTAMP_TZ,                           //defineTypeCode,                               //ub2         dty,
		unsafe.Pointer(&def.null),                     //void        *indp,
		nil,           //ub2         *rlenp,
		nil,           //ub2         *rcodep,
		C.OCI_DEFAULT) //ub4         mode );
	if r == C.OCI_ERROR {
		return def.rset.stmt.ses.srv.env.ociError()
	}
	return nil
}

func (def *defTime) value() (value interface{}, err error) {
	if def.isNullable {
		oraTimeValue := Time{IsNull: def.null < 0}
		if !oraTimeValue.IsNull {
			oraTimeValue.Value, err = getTime(def.rset.stmt.ses.srv.env, def.ociDateTime)
		}
		value = oraTimeValue
		return value, err
	}
	if def.null < 0 {
		return time.Time{}, nil // zero time
	}
	return getTime(def.rset.stmt.ses.srv.env, def.ociDateTime)
}

func (def *defTime) alloc() error {
	r := C.OCIDescriptorAlloc(
		unsafe.Pointer(def.rset.stmt.ses.srv.env.ocienv),    //CONST dvoid   *parenth,
		(*unsafe.Pointer)(unsafe.Pointer(&def.ociDateTime)), //dvoid         **descpp,
		C.OCI_DTYPE_TIMESTAMP_TZ,                            //ub4           type,
		0,   //size_t        xtramem_sz,
		nil) //dvoid         **usrmempp);
	if r == C.OCI_ERROR {
		return def.rset.stmt.ses.srv.env.ociError()
	} else if r == C.OCI_INVALID_HANDLE {
		return errNew("unable to allocate oci timestamp handle during define")
	}
	return nil

}

func (def *defTime) free() {
	defer func() {
		recover()
	}()
	C.OCIDescriptorFree(
		unsafe.Pointer(def.ociDateTime), //void     *descp,<commit_msg>Let defTime.value return nil for nil DATE<commit_after>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by The MIT License
// found in the accompanying LICENSE file.

package ora

/*
#include <oci.h>
#include "version.h"
*/
import "C"
import (
	"bytes"
	"math"
	"strings"
	"time"
	"unsafe"
)

type defTime struct {
	rset        *Rset
	ocidef      *C.OCIDefine
	ociDateTime *C.OCIDateTime
	null        C.sb2
	isNullable  bool
}

func (def *defTime) define(position int, isNullable bool, rset *Rset) error {
	def.rset = rset
	def.isNullable = isNullable
	r := C.OCIDEFINEBYPOS(
		def.rset.ocistmt,                              //OCIStmt     *stmtp,
		&def.ocidef,                                   //OCIDefine   **defnpp,
		def.rset.stmt.ses.srv.env.ocierr,              //OCIError    *errhp,
		C.ub4(position),                               //ub4         position,
		unsafe.Pointer(&def.ociDateTime),              //void        *valuep,
		C.LENGTH_TYPE(unsafe.Sizeof(def.ociDateTime)), //sb8         value_sz,
		C.SQLT_TIMESTAMP_TZ,                           //defineTypeCode,                               //ub2         dty,
		unsafe.Pointer(&def.null),                     //void        *indp,
		nil,           //ub2         *rlenp,
		nil,           //ub2         *rcodep,
		C.OCI_DEFAULT) //ub4         mode );
	if r == C.OCI_ERROR {
		return def.rset.stmt.ses.srv.env.ociError()
	}
	return nil
}

func (def *defTime) value() (value interface{}, err error) {
	if def.isNullable {
		oraTimeValue := Time{IsNull: def.null < 0}
		if !oraTimeValue.IsNull {
			oraTimeValue.Value, err = getTime(def.rset.stmt.ses.srv.env, def.ociDateTime)
		}
		return oraTimeValue, err
	}
	if def.null < 0 {
		return nil, nil
	}
	return getTime(def.rset.stmt.ses.srv.env, def.ociDateTime)
}

func (def *defTime) alloc() error {
	r := C.OCIDescriptorAlloc(
		unsafe.Pointer(def.rset.stmt.ses.srv.env.ocienv),    //CONST dvoid   *parenth,
		(*unsafe.Pointer)(unsafe.Pointer(&def.ociDateTime)), //dvoid         **descpp,
		C.OCI_DTYPE_TIMESTAMP_TZ,                            //ub4           type,
		0,   //size_t        xtramem_sz,
		nil) //dvoid         **usrmempp);
	if r == C.OCI_ERROR {
		return def.rset.stmt.ses.srv.env.ociError()
	} else if r == C.OCI_INVALID_HANDLE {
		return errNew("unable to allocate oci timestamp handle during define")
	}
	return nil

}

func (def *defTime) free() {
	defer func() {
		recover()
	}()
	C.OCIDescriptorFree(
		unsafe.Pointer(def.ociDateTime), //void     *descp,
{'fraction_non_alphanumeric': 0.13007325282122353, 'fraction_numerical': 0.006335379132844981, 'mean_word_length': 2.0305938812237554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6974379', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1803, 'n_words': 397}