Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3e2fa74004 | ||
![]() |
b9d27b0dbc | ||
![]() |
1f46b0a708 | ||
![]() |
6eb67283df | ||
![]() |
544701b4d8 | ||
![]() |
48e24e8b76 | ||
![]() |
77d04c9e82 | ||
![]() |
901b322819 | ||
![]() |
6f0b5ba942 | ||
![]() |
07fa912c18 |
9
build.sh
9
build.sh
@ -48,6 +48,7 @@ else
|
||||
echo "Kernel is $kernel"
|
||||
exit 1
|
||||
fi
|
||||
os_version=$(cat /etc/os-release | grep -w VERSION_ID | awk -F '"' '{print $2}')
|
||||
|
||||
#######################################################################
|
||||
## print help information
|
||||
@ -62,8 +63,8 @@ function print_help()
|
||||
}
|
||||
|
||||
##default install version storage path
|
||||
declare db_name_for_package='openGauss'
|
||||
declare version_number='5.0.0'
|
||||
declare db_name_for_package='openGauss-Python'
|
||||
declare version_number='6.0.0'
|
||||
|
||||
if [ $# = 0 ] ; then
|
||||
echo "missing option"
|
||||
@ -118,8 +119,8 @@ done
|
||||
## declare all package name
|
||||
#######################################################################
|
||||
declare version_string="${db_name_for_package}-${version_number}"
|
||||
declare package_pre_name="${version_string}-${dist_version}-${PLATFORM}"
|
||||
declare python_package_name="${package_pre_name}-Python.${install_package_format}.gz"
|
||||
declare package_pre_name="${version_string}-${dist_version}${os_version}-${PLATFORM}"
|
||||
declare python_package_name="${package_pre_name}.${install_package_format}.gz"
|
||||
|
||||
declare BUILD_DIR="${LOCAL_DIR}/build"
|
||||
declare MKGS_OK=0
|
||||
|
@ -49,7 +49,7 @@ extern "C" {
|
||||
/* sql_compatibility values */
|
||||
#define SQL_COMPATIBILITY_A 1
|
||||
#define SQL_COMPATIBILITY_OTHER 5
|
||||
// #define SQL_COMPATIBILITY_B 2
|
||||
#define SQL_COMPATIBILITY_B 2
|
||||
// #define SQL_COMPATIBILITY_C 3
|
||||
// #define SQL_COMPATIBILITY_PG 4
|
||||
|
||||
|
@ -1356,14 +1356,32 @@ register_type_uint(connectionObject *self, PyThreadState **tstate)
|
||||
}
|
||||
if (typecast_add((PyObject *)obj, self->string_types, 0) < 0) { goto end; }
|
||||
rv = 0;
|
||||
free(_typecast_INTEGER_types);
|
||||
end:
|
||||
free(_typecast_INTEGER_types);
|
||||
Py_XDECREF(values);
|
||||
Py_XDECREF(name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
static int set_sql_compatibility(connectionObject *self, char *value)
|
||||
{
|
||||
switch (value[0]) {
|
||||
case 'A':
|
||||
case 'a':
|
||||
self->sql_compatibility = SQL_COMPATIBILITY_A;
|
||||
break;
|
||||
case 'B':
|
||||
case 'b':
|
||||
self->sql_compatibility = SQL_COMPATIBILITY_B;
|
||||
break;
|
||||
default:
|
||||
self->sql_compatibility = SQL_COMPATIBILITY_OTHER;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* initialization and finalization methods */
|
||||
|
||||
static int
|
||||
@ -1410,19 +1428,25 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
||||
Dprintf("connection_setup: good connection object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
self, Py_REFCNT(self));
|
||||
PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState));
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
pthread_mutex_lock(&self->lock);
|
||||
sql_compatibility_value = pq_get_guc_locked(self, "sql_compatibility", &_save);
|
||||
if (register_type_uint(self, &_save)) { goto exit; }
|
||||
set_sql_compatibility(self, sql_compatibility_value);
|
||||
memcpy(tstate, _save, sizeof(_save));
|
||||
pthread_mutex_unlock(&self->lock);
|
||||
Py_END_ALLOW_THREADS;
|
||||
|
||||
if (strcmp(sql_compatibility_value, "A") == 0) {
|
||||
self->sql_compatibility = SQL_COMPATIBILITY_A;
|
||||
} else {
|
||||
self->sql_compatibility = SQL_COMPATIBILITY_OTHER;
|
||||
|
||||
pthread_mutex_lock(&self->lock);
|
||||
if (register_type_uint(self, &tstate)) {
|
||||
goto exit;
|
||||
}
|
||||
if (tstate) {
|
||||
free(tstate);
|
||||
tstate = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&self->lock);
|
||||
|
||||
exit:
|
||||
if (sql_compatibility_value){
|
||||
|
@ -57,6 +57,16 @@ curs_get_cast(cursorObject *self, PyObject *oid)
|
||||
if (cast) { return cast; }
|
||||
|
||||
/* global lookup */
|
||||
if (self->conn->sql_compatibility == SQL_COMPATIBILITY_B) {
|
||||
/*
|
||||
In mysql compatibility mode, we should convert the TIME column to a python datetime.timedelta type,
|
||||
just like the behavior of PyMySQL and mysql-connector-python.
|
||||
*/
|
||||
if (PyLong_Check(oid)) {
|
||||
long value = convert_time_oid_to_interval_oid(PyLong_AsLong(oid));
|
||||
oid = PyLong_FromLong(value);
|
||||
}
|
||||
}
|
||||
cast = PyDict_GetItem(psyco_types, oid);
|
||||
Dprintf("curs_get_cast: global dict: %p", cast);
|
||||
if (cast) { return cast; }
|
||||
|
@ -616,7 +616,7 @@ pq_get_pg_catalog_custom_type_oid(connectionObject *conn, const char *param, PyT
|
||||
char query[256];
|
||||
int size;
|
||||
unsigned int rv = 0;
|
||||
|
||||
char *temp_oid = NULL;
|
||||
size = PyOS_snprintf(query, sizeof(query), "select oid from pg_type where typnamespace = 11 and typname= %s", param);
|
||||
if (size < 0 || (size_t)size >= sizeof(query)) {
|
||||
conn_set_error(conn, "query too large");
|
||||
@ -645,8 +645,10 @@ pq_get_pg_catalog_custom_type_oid(connectionObject *conn, const char *param, PyT
|
||||
PQresStatus(PQresultStatus(conn->pgres)));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rv = atoi(strdup(PQgetvalue(conn->pgres, 0, 0)));
|
||||
temp_oid = PQgetvalue(conn->pgres, 0, 0);
|
||||
if (temp_oid) {
|
||||
rv = (unsigned int)atoi(temp_oid);
|
||||
}
|
||||
CLEARPGRES(conn->pgres);
|
||||
|
||||
cleanup:
|
||||
|
@ -88,5 +88,7 @@ HIDDEN PyObject *typecast_array_from_python(
|
||||
HIDDEN PyObject *typecast_cast(
|
||||
PyObject *self, const char *str, Py_ssize_t len, PyObject *curs);
|
||||
|
||||
HIDDEN long convert_time_oid_to_interval_oid(long value);
|
||||
|
||||
#endif /* !defined(PSYCOPG_TYPECAST_H) */
|
||||
PyObject *typecast_new(PyObject *name, PyObject *values, PyObject *cast, PyObject *base);
|
@ -31,6 +31,21 @@ static long int typecast_MACADDRARRAY_types[] = {1040, 0};
|
||||
static long int typecast_UNKNOWN_types[] = {705, 0};
|
||||
|
||||
|
||||
long convert_time_oid_to_interval_oid(long value)
|
||||
{
|
||||
int i = 0;
|
||||
while (typecast_TIME_types[i] != 0) {
|
||||
if (typecast_TIME_types[i] == value) {
|
||||
Dprintf("convert time oid to interval oid");
|
||||
value = typecast_INTERVAL_types[0];
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
static typecastObject_initlist typecast_builtins[] = {
|
||||
{"NUMBER", typecast_NUMBER_types, typecast_NUMBER_cast, NULL},
|
||||
{"LONGINTEGER", typecast_LONGINTEGER_types, typecast_LONGINTEGER_cast, NULL},
|
||||
|
@ -203,6 +203,11 @@ _parse_noninftz(const char *str, Py_ssize_t len, PyObject *curs)
|
||||
rv = PyObject_CallFunction(
|
||||
(PyObject*)PyDateTimeAPI->DateTimeType, "iiiiiiiO",
|
||||
y, m, d, hh, mm, ss, us, tzinfo);
|
||||
if (rv == NULL) {
|
||||
/* illegal values are returned as str */
|
||||
PyErr_Clear();
|
||||
rv = PyUnicode_FromString(str);
|
||||
}
|
||||
|
||||
exit:
|
||||
Py_XDECREF(tzoff);
|
||||
|
Loading…
x
Reference in New Issue
Block a user