Skip to content

Commit 29def58

Browse files
committed
Add support for MAX_IDENTIFIER_LENGTH value of the database
1 parent 7ad1448 commit 29def58

File tree

12 files changed

+93
-10
lines changed

12 files changed

+93
-10
lines changed

doc/src/api_manual/connection.rst

+14
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ The properties of a *Connection* object are listed below.
191191
associated with the connection. It returns the same value as the SQL expression
192192
``sys_context('userenv', 'instance_name')``.
193193

194+
.. attribute:: connection.maxIdentifierLength
195+
196+
.. versionadded:: 6.8
197+
198+
This read-only attribute specifies the maximum database identifier length
199+
in bytes supported by the database to which the connection has been
200+
established. See `Database Object Naming Rules
201+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
202+
id=GUID-75337742-67FD-4EC0-985F-741C93D918DA>`__. The value may be
203+
*undefined*, *30*, or *128*. The value *undefined* indicates the size
204+
cannot be reliably determined by node-oracledb, which occurs when using
205+
Oracle Client libraries 12.1 (or older) to connect to Oracle Database
206+
12.2, or later.
207+
194208
.. attribute:: connection.maxOpenCursors
195209

196210
.. versionadded:: 6.3

doc/src/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# General substitutions.
3737
project = 'node-oracledb'
38-
copyright = u'2015, 2024, Oracle and/or its affiliates'
38+
copyright = u'2015, 2025, Oracle and/or its affiliates'
3939
author = 'Oracle'
4040

4141
# The default replacements for |version| and |release|, also used in various

doc/src/license.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ License
1010

1111
.. centered:: **LICENSE AGREEMENT FOR node-oracledb**
1212

13-
Copyright |copy| 2015, 2024 Oracle and/or its affiliates.
13+
Copyright |copy| 2015, 2025 Oracle and/or its affiliates.
1414

1515
This software is dual-licensed to you under the Universal Permissive License
1616
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License

doc/src/release_notes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Common Changes
1919
#) Fixed :attr:`~dbObject.length` property for the database object
2020
collection types, which was broken from node-oracledb 6.0.
2121

22+
#) Added support for returning maximum identifier length allowed by the
23+
database using the new property :attr:`connection.maxIdentifierLength`.
24+
2225
Thin Mode Changes
2326
+++++++++++++++++
2427

examples/connect.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2024, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2015, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -70,9 +70,12 @@ async function run() {
7070
try {
7171
// Get a non-pooled connection
7272
connection = await oracledb.getConnection(dbConfig);
73-
7473
console.log('Connection was successful!');
7574

75+
// Check some connection properties
76+
console.log('Maximum Open Cursors:', connection.maxOpenCursors);
77+
console.log('Maximum Identifier Length:', connection.maxIdentifierLength);
78+
7679
} catch (err) {
7780
console.error(err);
7881
} finally {

lib/connection.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2016, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -1216,6 +1216,16 @@ class Connection extends EventEmitter {
12161216
this._impl.isHealthy());
12171217
}
12181218

1219+
//---------------------------------------------------------------------------
1220+
// maxIdentifierLength
1221+
//
1222+
// Returns the maximum length of identifiers supported by the database to
1223+
// which this connection has been established.
1224+
//---------------------------------------------------------------------------
1225+
get maxIdentifierLength() {
1226+
return this._impl && this._impl.getMaxIdentifierLength();
1227+
}
1228+
12191229
//---------------------------------------------------------------------------
12201230
// maxOpenCursors
12211231
//

lib/impl/connection.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -289,6 +289,16 @@ class ConnectionImpl {
289289
errors.throwNotImplemented("getting the internal name");
290290
}
291291

292+
//---------------------------------------------------------------------------
293+
// getMaxIdentifierLength()
294+
//
295+
// Returns the maximum length of identifiers supported by the database to
296+
// which this connection has been established.
297+
//---------------------------------------------------------------------------
298+
getMaxIdentifierLength() {
299+
errors.throwNotImplemented("getting the maximum identifier length");
300+
}
301+
292302
//---------------------------------------------------------------------------
293303
// getMaxOpenCursors()
294304
//

lib/thin/connection.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -1312,6 +1312,14 @@ class ThinConnectionImpl extends ConnectionImpl {
13121312
return this.maxOpenCursors;
13131313
}
13141314

1315+
//---------------------------------------------------------------------------
1316+
// Returns the maximum length of identifiers supported by the database to
1317+
// which this connection has been established.
1318+
//---------------------------------------------------------------------------
1319+
getMaxIdentifierLength() {
1320+
return this.maxIdentifierLength;
1321+
}
1322+
13151323
//---------------------------------------------------------------------------
13161324
// Returns the Oracle Database service name associated with the connection.
13171325
//---------------------------------------------------------------------------

lib/thin/protocol/messages/auth.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -342,6 +342,7 @@ class AuthMessage extends Message {
342342
this.conn.maxOpenCursors = Number(this.sessionData['AUTH_MAX_OPEN_CURSORS'] || 0);
343343
this.conn.serviceName = this.sessionData['AUTH_SC_SERVICE_NAME'];
344344
this.conn.instanceName = this.sessionData['AUTH_INSTANCENAME'];
345+
this.conn.maxIdentifierLength = Number(this.sessionData['AUTH_MAX_IDEN_LENGTH'] || 30);
345346
const fullVersionNum = Number(this.sessionData['AUTH_VERSION_NO']);
346347
const versionNum = (fullVersionNum >> 24) & 0xFF;
347348
this.conn.warning = this.warning;

src/njsConnection.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2015, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -49,6 +49,7 @@ NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getExternalName);
4949
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getInstanceName);
5050
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getInternalName);
5151
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getMaxOpenCursors);
52+
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getMaxIdentifierLength);
5253
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getOracleServerVersion);
5354
NJS_NAPI_METHOD_DECL_SYNC(njsConnection_getOracleServerVersionString);
5455
NJS_NAPI_METHOD_DECL_ASYNC(njsConnection_getQueue);
@@ -157,6 +158,8 @@ static const napi_property_descriptor njsClassProperties[] = {
157158
napi_default, NULL },
158159
{ "getMaxOpenCursors", NULL, njsConnection_getMaxOpenCursors, NULL, NULL,
159160
NULL, napi_default, NULL },
161+
{ "getMaxIdentifierLength", NULL, njsConnection_getMaxIdentifierLength, NULL, NULL,
162+
NULL, napi_default, NULL },
160163
{ "getOracleServerVersion", NULL, njsConnection_getOracleServerVersion,
161164
NULL, NULL, NULL, napi_default, NULL },
162165
{ "getOracleServerVersionString", NULL,
@@ -1236,6 +1239,29 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsConnection_getMaxOpenCursors, 0, NULL)
12361239
return true;
12371240
}
12381241

1242+
//-----------------------------------------------------------------------------
1243+
// njsConnection_getMaxIdentifierLength()
1244+
// Get accessor of "maxIdentifierLength" property.
1245+
//-----------------------------------------------------------------------------
1246+
NJS_NAPI_METHOD_IMPL_SYNC(njsConnection_getMaxIdentifierLength, 0, NULL)
1247+
{
1248+
njsConnection *conn = (njsConnection*) callingInstance;
1249+
dpiConnInfo connInfo;
1250+
1251+
if (conn->handle) {
1252+
if (dpiConn_getInfo(conn->handle, &connInfo) < 0)
1253+
return njsUtils_throwErrorDPI(env, globals);
1254+
// The check below is made, because Oracle Client does not return the
1255+
// max identifier length reliably when using Oracle Client
1256+
// 12.1 (or lower) to connect to Oracle Database 12.2 (or higher).
1257+
// See https://github.com/oracle/python-oracledb/issues/395
1258+
if (connInfo.maxIdentifierLength != 0)
1259+
NJS_CHECK_NAPI(env, napi_create_uint32(env, connInfo.maxIdentifierLength,
1260+
returnValue))
1261+
}
1262+
return true;
1263+
}
1264+
12391265

12401266
//-----------------------------------------------------------------------------
12411267
// njsConnection_getExecuteManyOutBinds()

test/connProps.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2024, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -235,4 +235,11 @@ describe('193. connProps.js', function() {
235235
await conn.execute(`DROP TABLE ${TABLE} PURGE`);
236236
await conn.close();
237237
}); // 193.10
238+
239+
it('193.11 maximum identifier length', async () => {
240+
const conn = await oracledb.getConnection(dbConfig);
241+
if (conn.maxIdentifierLength)
242+
assert.strictEqual(typeof conn.maxIdentifierLength, "number");
243+
await conn.close();
244+
}); // 193.11
238245
});

test/list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4615,6 +4615,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
46154615
193.8 maximum cursors that can be opened on a connection
46164616
193.9 transactionInProgress = false on a connection for query
46174617
193.10 transactionInProgress = true on a connection
4618+
193.11 maximum identifier length
46184619

46194620
196. getDataOfLob.js
46204621
196.1 getData() works on CLOB

0 commit comments

Comments
 (0)