Compare commits

...

10 Commits

Author SHA1 Message Date
opengauss_bot
3e2fa74004
!33 解决python3.9连接数据库挂掉问题
Merge pull request !33 from zcl/6.0.0-bug1
2024-09-26 02:08:38 +00:00
zcl
b9d27b0dbc 解决python3.9连接数据库挂掉问题 2024-09-25 17:31:03 +08:00
opengauss_bot
1f46b0a708
!31 Cherry pick !29 to branch 6.0.0
Merge pull request !31 from vimiix/yq/fix-IAIE7I
2024-09-25 09:08:22 +00:00
vimiix
6eb67283df
fix: use timedelta instead of time to cast TIME column in B compatibility mode(#IAIE7I)
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.

See also:
- PyMySQL: 95635f587b/pymysql/converters.py (L344)
- mysql-connector-python: 59817f3de4/mysql-connector-python/lib/mysql/connector/conversion.py (L593)
2024-09-04 15:49:24 +08:00
opengauss_bot
544701b4d8
!30 解决当数据库后台查询不到uint1、uint2、uint4、uint8类型的oid导致驱动挂掉问题
Merge pull request !30 from zcl/r-branch-v6
2024-09-04 02:12:13 +00:00
zcl
48e24e8b76 解决当数据库后台查询不到uint1、uint2、uint4、uint8类型的oid导致驱动挂掉问题
(cherry picked from commit de9de1acc92ea861875c96367132651c8420e26e)

静态检查

codecheck2
2024-08-28 15:56:42 +08:00
opengauss_bot
77d04c9e82
!28 cherry-pick: illegal datetime values are returned as str(#I90GIP)
Merge pull request !28 from vimiix/cherry-pick-3d2f2c2
2024-08-20 10:50:53 +00:00
vimiix
901b322819 feat: illegal datetime values are returned as str(#I90GIP) 2024-08-20 17:46:56 +08:00
opengauss_bot
6f0b5ba942
!26 更新社区包名称,明确区分各个系统和架构
Merge pull request !26 from zhangxubo/fixver
2024-08-09 06:41:47 +00:00
zhang_xubo
07fa912c18 更新包名 2024-08-05 19:50:10 +08:00
8 changed files with 74 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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){

View File

@ -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; }

View File

@ -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:

View File

@ -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);

View File

@ -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},

View File

@ -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);