Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
c92f2606
Commit
c92f2606
authored
May 21, 2016
by
Olivier Bertrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit changes made from 10.1
parent
4a1ffc38
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
453 additions
and
332 deletions
+453
-332
storage/connect/ha_connect.cc
storage/connect/ha_connect.cc
+23
-11
storage/connect/jdbconn.cpp
storage/connect/jdbconn.cpp
+285
-304
storage/connect/jdbconn.h
storage/connect/jdbconn.h
+25
-3
storage/connect/tabjdbc.cpp
storage/connect/tabjdbc.cpp
+117
-14
storage/connect/tabjdbc.h
storage/connect/tabjdbc.h
+3
-0
No files found.
storage/connect/ha_connect.cc
View file @
c92f2606
...
...
@@ -119,6 +119,7 @@
#undef OFFSET
#define NOPARSE
#define NJDBC
#if defined(UNIX)
#include "osutil.h"
#endif // UNIX
...
...
@@ -128,7 +129,7 @@
#include "odbccat.h"
#endif // ODBC_SUPPORT
#if defined(JDBC_SUPPORT)
#include "
jdbccat
.h"
#include "
tabjdbc
.h"
#include "jdbconn.h"
#endif // JDBC_SUPPORT
#include "xtable.h"
...
...
@@ -5224,7 +5225,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif
#if defined(JDBC_SUPPORT)
driver
=
GetListOption
(
g
,
"Driver"
,
topt
->
oplist
,
NULL
);
url
=
GetListOption
(
g
,
"URL"
,
topt
->
oplist
,
NULL
);
//
url= GetListOption(g, "URL", topt->oplist, NULL);
tabtyp
=
GetListOption
(
g
,
"Tabtype"
,
topt
->
oplist
,
NULL
);
#endif // JDBC_SUPPORT
mxe
=
atoi
(
GetListOption
(
g
,
"maxerr"
,
topt
->
oplist
,
"0"
));
...
...
@@ -5325,18 +5326,31 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case
TAB_JDBC
:
if
(
fnc
&
FNC_DRIVER
)
{
ok
=
true
;
}
else
if
(
!
url
&&
!
(
url
=
strz
(
g
,
create_info
->
connect_string
)))
{
}
else
if
(
!
(
url
=
strz
(
g
,
create_info
->
connect_string
)))
{
strcpy
(
g
->
Message
,
"Missing URL"
);
}
else
{
// Store ODBC additional parameters
// Store JDBC additional parameters
int
rc
;
PJDBCDEF
jdef
=
new
(
g
)
JDBCDEF
();
jdef
->
SetName
(
create_info
->
alias
);
sjp
=
(
PJPARM
)
PlugSubAlloc
(
g
,
NULL
,
sizeof
(
JDBCPARM
));
sjp
->
Driver
=
driver
;
sjp
->
Fsize
=
0
;
sjp
->
Scrollable
=
false
;
if
((
rc
=
jdef
->
ParseURL
(
g
,
url
,
false
))
==
RC_OK
)
{
sjp
->
Url
=
url
;
sjp
->
User
=
(
char
*
)
user
;
sjp
->
Pwd
=
(
char
*
)
pwd
;
sjp
->
Fsize
=
0
;
sjp
->
Scrollable
=
false
;
ok
=
true
;
}
else
if
(
rc
==
RC_NF
)
{
if
(
jdef
->
GetTabname
())
tab
=
jdef
->
GetTabname
();
ok
=
jdef
->
SetParms
(
sjp
);
}
// endif rc
}
// endif's
supfnc
|=
(
FNC_DRIVER
|
FNC_TABLE
);
...
...
@@ -5775,12 +5789,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
switch
(
typ
)
{
case
TYPE_DOUBLE
:
case
TYPE_DECIM
:
// Some data sources do not count dec in length (prec)
prec
+=
(
dec
+
2
);
// To be safe
break
;
case
TYPE_DECIM
:
prec
=
len
;
break
;
default:
dec
=
0
;
}
// endswitch typ
...
...
storage/connect/jdbconn.cpp
View file @
c92f2606
...
...
@@ -38,7 +38,6 @@
#include "plgdbsem.h"
#include "xobject.h"
#include "xtable.h"
#include "jdbccat.h"
#include "tabjdbc.h"
//#include "jdbconn.h"
//#include "plgcnx.h" // For DB types
...
...
@@ -63,6 +62,9 @@ extern char *ClassPath; // The connect_class_path global variable value
void
*
JDBConn
::
LibJvm
=
NULL
;
CRTJVM
JDBConn
::
CreateJavaVM
=
NULL
;
GETJVM
JDBConn
::
GetCreatedJavaVMs
=
NULL
;
#if defined(_DEBUG)
GETDEF
JDBConn
::
GetDefaultJavaVMInitArgs
=
NULL
;
#endif // _DEBUG
/***********************************************************************/
/* Some macro's (should be defined elsewhere to be more accessible) */
...
...
@@ -118,6 +120,7 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
break
;
case
2
:
// NUMERIC
case
3
:
// DECIMAL
case
-
3
:
// VARBINARY
type
=
TYPE_DECIM
;
break
;
case
4
:
// INTEGER
...
...
@@ -155,7 +158,6 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
break
;
case
0
:
// NULL
case
-
2
:
// BINARY
case
-
3
:
// VARBINARY
case
-
4
:
// LONGVARBINARY
default:
type
=
TYPE_ERROR
;
...
...
@@ -318,12 +320,15 @@ PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
/**************************************************************************/
PQRYRES
JDBCSrcCols
(
PGLOBAL
g
,
char
*
src
,
PJPARM
sjp
)
{
PQRYRES
qrp
;
JDBConn
*
jcp
=
new
(
g
)
JDBConn
(
g
,
NULL
);
if
(
jcp
->
Open
(
sjp
))
return
NULL
;
return
jcp
->
GetMetaData
(
g
,
src
);
qrp
=
jcp
->
GetMetaData
(
g
,
src
);
jcp
->
Close
();
return
qrp
;
}
// end of JDBCSrcCols
/**************************************************************************/
...
...
@@ -361,14 +366,14 @@ PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
n
=
jcp
->
GetMaxValue
(
2
);
// Max catalog name length
if
(
n
<
0
)
return
NULL
;
//
if (n < 0)
//
return NULL;
length
[
0
]
=
(
n
)
?
(
n
+
1
)
:
0
;
length
[
0
]
=
(
n
>
0
)
?
(
n
+
1
)
:
0
;
n
=
jcp
->
GetMaxValue
(
3
);
// Max schema name length
length
[
1
]
=
(
n
)
?
(
n
+
1
)
:
0
;
length
[
1
]
=
(
n
>
0
)
?
(
n
+
1
)
:
0
;
n
=
jcp
->
GetMaxValue
(
4
);
// Max table name length
length
[
2
]
=
(
n
)
?
(
n
+
1
)
:
128
;
length
[
2
]
=
(
n
>
0
)
?
(
n
+
1
)
:
128
;
}
else
{
maxres
=
0
;
length
[
0
]
=
128
;
...
...
@@ -642,11 +647,13 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
env
=
nullptr
;
// Pointer to native interface
jdi
=
nullptr
;
// Pointer to the JdbcInterface class
job
=
nullptr
;
// The JdbcInterface class object
xqid
=
xuid
=
xid
=
grs
=
readid
=
fetchid
=
typid
=
nullptr
;
xqid
=
xuid
=
xid
=
grs
=
readid
=
fetchid
=
typid
=
errid
=
nullptr
;
prepid
=
xpid
=
pcid
=
nullptr
;
chrfldid
=
intfldid
=
dblfldid
=
fltfldid
=
datfldid
=
bigfldid
=
nullptr
;
//m_LoginTimeout = DEFAULT_LOGIN_TIMEOUT;
//m_QueryTimeout = DEFAULT_QUERY_TIMEOUT;
//m_UpdateOptions = 0;
Msg
=
NULL
;
m_Driver
=
NULL
;
m_Url
=
NULL
;
m_User
=
NULL
;
...
...
@@ -676,10 +683,11 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
/***********************************************************************/
/* Screen for errors. */
/***********************************************************************/
char
*
JDBConn
::
Check
(
void
)
bool
JDBConn
::
Check
(
jint
rc
)
{
jstring
s
;
if
(
env
->
ExceptionCheck
())
{
char
*
msg
;
jthrowable
exc
=
env
->
ExceptionOccurred
();
jmethodID
tid
=
env
->
GetMethodID
(
env
->
FindClass
(
"java/lang/Object"
),
"toString"
,
"()Ljava/lang/String;"
);
...
...
@@ -688,17 +696,39 @@ char *JDBConn::Check(void)
jstring
s
=
(
jstring
)
env
->
CallObjectMethod
(
exc
,
tid
);
const
char
*
utf
=
env
->
GetStringUTFChars
(
s
,
(
jboolean
)
false
);
env
->
DeleteLocalRef
(
s
);
m
sg
=
PlugDup
(
m_G
,
utf
);
M
sg
=
PlugDup
(
m_G
,
utf
);
}
else
m
sg
=
"Exception occured"
;
M
sg
=
"Exception occured"
;
env
->
ExceptionClear
();
return
msg
;
}
// endif Check
}
else
if
(
rc
<
0
)
{
s
=
(
jstring
)
env
->
CallObjectMethod
(
job
,
errid
);
Msg
=
(
char
*
)
env
->
GetStringUTFChars
(
s
,
(
jboolean
)
false
);
}
else
Msg
=
NULL
;
return
NULL
;
return
(
Msg
!=
NULL
)
;
}
// end of Check
/***********************************************************************/
/* Get MethodID if not exists yet. */
/***********************************************************************/
bool
JDBConn
::
gmID
(
PGLOBAL
g
,
jmethodID
&
mid
,
const
char
*
name
,
const
char
*
sig
)
{
if
(
mid
==
nullptr
)
{
mid
=
env
->
GetMethodID
(
jdi
,
name
,
sig
);
if
(
Check
())
{
strcpy
(
g
->
Message
,
Msg
);
return
true
;
}
else
return
false
;
}
else
return
false
;
}
// end of gmID
#if 0
/***********************************************************************/
/* Utility routine. */
...
...
@@ -758,15 +788,17 @@ void JDBConn::OnSetOptions(HSTMT hstmt)
/***********************************************************************/
int
JDBConn
::
GetMaxValue
(
int
n
)
{
jmethodID
maxid
=
env
->
GetMethodID
(
jdi
,
"GetMaxValue"
,
"(I)I"
);
jint
m
;
jmethodID
maxid
=
nullptr
;
if
(
maxid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"ERROR: method GetMaxValue not found !"
);
if
(
gmID
(
m_G
,
maxid
,
"GetMaxValue"
,
"(I)I"
))
return
-
1
;
}
// endif maxid
// call method
return
(
int
)
env
->
CallIntMethod
(
job
,
maxid
,
n
);
if
(
Check
(
m
=
env
->
CallIntMethod
(
job
,
maxid
,
n
)))
htrc
(
"GetMaxValue: %s"
,
Msg
);
return
(
int
)
m
;
}
// end of GetMaxValue
/***********************************************************************/
...
...
@@ -783,6 +815,9 @@ void JDBConn::ResetJVM(void)
LibJvm
=
NULL
;
CreateJavaVM
=
NULL
;
GetCreatedJavaVMs
=
NULL
;
#if defined(_DEBUG)
GetDefaultJavaVMInitArgs
=
NULL
;
#endif // _DEBUG
}
// endif LibJvm
}
// end of ResetJVM
...
...
@@ -823,6 +858,14 @@ bool JDBConn::GetJVM(PGLOBAL g)
sprintf
(
g
->
Message
,
MSG
(
PROCADD_ERROR
),
GetLastError
(),
"JNI_GetCreatedJavaVMs"
);
FreeLibrary
((
HMODULE
)
LibJvm
);
LibJvm
=
NULL
;
#if defined(_DEBUG)
}
else
if
(
!
(
GetDefaultJavaVMInitArgs
=
(
GETDEF
)
GetProcAddress
((
HINSTANCE
)
LibJvm
,
"JNI_GetDefaultJavaVMInitArgs"
)))
{
sprintf
(
g
->
Message
,
MSG
(
PROCADD_ERROR
),
GetLastError
(),
"JNI_GetDefaultJavaVMInitArgs"
);
FreeLibrary
((
HMODULE
)
LibJvm
);
LibJvm
=
NULL
;
#endif // _DEBUG
}
// endif LibJvm
#else // !__WIN__
const
char
*
error
=
NULL
;
...
...
@@ -846,6 +889,14 @@ bool JDBConn::GetJVM(PGLOBAL g)
sprintf
(
g
->
Message
,
MSG
(
GET_FUNC_ERR
),
"JNI_GetCreatedJavaVMs"
,
SVP
(
error
));
dlclose
(
LibJvm
);
LibJvm
=
NULL
;
#if defined(_DEBUG)
}
else
if
(
!
(
GetDefaultJavaVMInitArgs
=
(
GETDEF
)
dlsym
(
LibJvm
,
"JNI_GetDefaultJavaVMInitArgs"
)))
{
error
=
dlerror
();
sprintf
(
g
->
Message
,
MSG
(
GET_FUNC_ERR
),
"JNI_GetDefaultJavaVMInitArgs"
,
SVP
(
error
));
dlclose
(
LibJvm
);
LibJvm
=
NULL
;
#endif // _DEBUG
}
// endif LibJvm
#endif // !__WIN__
...
...
@@ -859,6 +910,7 @@ bool JDBConn::GetJVM(PGLOBAL g)
/***********************************************************************/
int
JDBConn
::
Open
(
PJPARM
sop
)
{
bool
err
=
false
;
PGLOBAL
&
g
=
m_G
;
// Link or check whether jvm library was linked
...
...
@@ -881,44 +933,59 @@ int JDBConn::Open(PJPARM sop)
}
// endif rc
}
else
{
// Create a new jvm
PSTRG
jpop
=
new
(
g
)
STRING
(
g
,
512
,
"-Djava.class.path="
);
/*******************************************************************/
/* Create a new jvm */
/*******************************************************************/
PSTRG
jpop
=
new
(
g
)
STRING
(
g
,
512
,
"-Djava.class.path=."
);
char
*
cp
=
NULL
;
char
sep
;
#if defined(__WIN__)
sep
=
';'
;
#define N 1
//#define N 2
//#define N 3
#else
sep
=
':'
;
#define N 1
#endif
//================== prepare loading of Java VM ============================
JavaVMInitArgs
vm_args
;
// Initialization arguments
JavaVMOption
*
options
=
new
JavaVMOption
[
1
];
// JVM invocation options
JavaVMOption
*
options
=
new
JavaVMOption
[
N
];
// JVM invocation options
// where to find java .class
if
((
cp
=
PlugDup
(
m_G
,
getenv
(
"CLASSPATH"
))))
jpop
->
Append
(
cp
);
if
(
trace
)
{
htrc
(
"CLASSPATH=%s
\n
"
,
getenv
(
"CLASSPATH"
));
htrc
(
"ClassPath=%s
\n
"
,
ClassPath
);
}
// endif trace
if
(
ClassPath
&&
*
ClassPath
)
{
if
(
cp
)
jpop
->
Append
(
sep
);
jpop
->
Append
(
ClassPath
);
}
// endif ClassPath
if
(
trace
)
if
((
cp
=
getenv
(
"CLASSPATH"
)))
{
jpop
->
Append
(
sep
);
jpop
->
Append
(
cp
);
}
// endif cp
if
(
trace
)
{
htrc
(
"ClassPath=%s
\n
"
,
ClassPath
);
htrc
(
"CLASSPATH=%s
\n
"
,
cp
);
htrc
(
"%s
\n
"
,
jpop
->
GetStr
());
}
// endif trace
options
[
0
].
optionString
=
jpop
->
GetStr
();
//options[1].optionString = "-verbose:jni";
#if N == 2
options
[
1
].
optionString
=
"-Xcheck:jni"
;
#endif
#if N == 3
options
[
1
].
optionString
=
"-Xms256M"
;
options
[
2
].
optionString
=
"-Xmx512M"
;
#endif
#if defined(_DEBUG)
vm_args
.
version
=
JNI_VERSION_1_2
;
// minimum Java version
rc
=
GetDefaultJavaVMInitArgs
(
&
vm_args
);
#else
vm_args
.
version
=
JNI_VERSION_1_6
;
// minimum Java version
vm_args
.
nOptions
=
1
;
// number of options
#endif // _DEBUG
vm_args
.
nOptions
=
N
;
// number of options
vm_args
.
options
=
options
;
vm_args
.
ignoreUnrecognized
=
false
;
// invalid options make the JVM init fail
...
...
@@ -956,8 +1023,10 @@ int JDBConn::Open(PJPARM sop)
}
// endif rc
//=============== Display JVM version =======================================
//jint ver = env->GetVersion();
//cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl;
#if defined(_DEBUG)
jint
ver
=
env
->
GetVersion
();
printf
(
"JVM Version %d.%d
\n
"
,
((
ver
>>
16
)
&
0x0f
),
(
ver
&
0x0f
));
#endif //_DEBUG
// try to find the JdbcInterface class
jdi
=
env
->
FindClass
(
"JdbcInterface"
);
...
...
@@ -981,7 +1050,7 @@ int JDBConn::Open(PJPARM sop)
jstring path = env->NewStringUTF(jpath);
rc = env->CallStaticIntMethod(jdi, alp, path);
if ((msg = Check())) {
if ((msg = Check(
rc
))) {
strcpy(g->Message, msg);
env->DeleteLocalRef(path);
return RC_FX;
...
...
@@ -1022,23 +1091,27 @@ int JDBConn::Open(PJPARM sop)
return
RC_FX
;
}
// endif job
if
(
!
sop
)
// DRIVER catalog table
return
RC_OK
;
jmethodID
cid
=
env
->
GetMethodID
(
jdi
,
"JdbcConnect"
,
"([Ljava/lang/String;IZ)I"
);
errid
=
env
->
GetMethodID
(
jdi
,
"GetErrmsg"
,
"()Ljava/lang/String;"
);
if
(
env
->
ExceptionCheck
())
{
strcpy
(
g
->
Message
,
"ERROR: method
JdbcConnect
() not found!"
);
strcpy
(
g
->
Message
,
"ERROR: method
GetErrmsg
() not found!"
);
env
->
ExceptionDescribe
();
env
->
ExceptionClear
();
return
RC_FX
;
}
// endif Check
if
(
!
sop
)
// DRIVER catalog table
return
RC_OK
;
jmethodID
cid
=
nullptr
;
if
(
gmID
(
g
,
cid
,
"JdbcConnect"
,
"([Ljava/lang/String;IZ)I"
))
return
RC_FX
;
// Build the java string array
jobjectArray
parms
=
env
->
NewObjectArray
(
4
,
// constructs java array of 4
env
->
FindClass
(
"java/lang/String"
),
NULL
);
// Strings
if
(
sop
)
{
m_Driver
=
sop
->
Driver
;
m_Url
=
sop
->
Url
;
m_User
=
sop
->
User
;
...
...
@@ -1048,7 +1121,6 @@ int JDBConn::Open(PJPARM sop)
//m_LoginTimeout = sop->Cto;
//m_QueryTimeout = sop->Qto;
//m_UseCnc = sop->UseCnc;
}
// endif sop
// change some elements
if
(
m_Driver
)
...
...
@@ -1065,23 +1137,17 @@ int JDBConn::Open(PJPARM sop)
// call method
rc
=
env
->
CallIntMethod
(
job
,
cid
,
parms
,
m_RowsetSize
,
m_Scrollable
);
err
=
Check
(
rc
);
env
->
DeleteLocalRef
(
parms
);
// Not used anymore
// Not used anymore
env
->
DeleteLocalRef
(
parms
);
if
(
rc
!=
(
jint
)
0
)
{
strcpy
(
g
->
Message
,
"Connection failed"
);
if
(
err
)
{
sprintf
(
g
->
Message
,
"Connecting: %s rc=%d"
,
Msg
,
(
int
)
rc
);
return
RC_FX
;
}
// endif rc
}
// endif Msg
typid
=
env
->
GetMethodID
(
jdi
,
"ColumnType"
,
"(ILjava/lang/String;)I"
);
if
(
env
->
ExceptionCheck
())
{
strcpy
(
g
->
Message
,
"ERROR: method ColumnType() not found!"
);
env
->
ExceptionDescribe
();
env
->
ExceptionClear
();
if
(
gmID
(
g
,
typid
,
"ColumnType"
,
"(ILjava/lang/String;)I"
))
return
RC_FX
;
}
else
else
m_Opened
=
true
;
return
RC_OK
;
...
...
@@ -1092,43 +1158,37 @@ int JDBConn::Open(PJPARM sop)
/***********************************************************************/
int
JDBConn
::
ExecSQLcommand
(
char
*
sql
)
{
int
rc
=
RC_NF
;
int
rc
;
jint
n
;
jstring
qry
;
PGLOBAL
&
g
=
m_G
;
if
(
xid
==
nullptr
)
{
// Get the methods used to execute a query and get the result
xid
=
env
->
GetMethodID
(
jdi
,
"Execute"
,
"(Ljava/lang/String;)I"
);
if
(
xid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method Execute"
);
return
RC_FX
;
}
else
grs
=
env
->
GetMethodID
(
jdi
,
"GetResult"
,
"()I"
);
if
(
grs
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method GetResult"
);
if
(
gmID
(
g
,
xid
,
"Execute"
,
"(Ljava/lang/String;)I"
)
||
gmID
(
g
,
grs
,
"GetResult"
,
"()I"
))
return
RC_FX
;
}
// endif grs
}
// endif xid
qry
=
env
->
NewStringUTF
(
sql
);
n
=
env
->
CallIntMethod
(
job
,
xid
,
qry
);
env
->
DeleteLocalRef
(
qry
);
if
(
n
<
0
)
{
sprintf
(
g
->
Message
,
"E
rror executing %s"
,
sql
);
if
(
Check
(
n
)
)
{
sprintf
(
g
->
Message
,
"E
xecute: %s"
,
Msg
);
return
RC_FX
;
}
// endif n
if
((
m_Ncol
=
env
->
CallIntMethod
(
job
,
grs
)))
{
m_Ncol
=
env
->
CallIntMethod
(
job
,
grs
);
if
(
Check
(
m_Ncol
))
{
sprintf
(
g
->
Message
,
"GetResult: %s"
,
Msg
);
rc
=
RC_FX
;
}
else
if
(
m_Ncol
)
{
strcpy
(
g
->
Message
,
"Result set column number"
);
rc
=
RC_OK
;
// A result set was returned
}
else
{
m_Aff
=
(
int
)
n
;
// Affected rows
strcpy
(
g
->
Message
,
"Affected rows"
);
rc
=
RC_NF
;
}
// endif ncol
return
rc
;
...
...
@@ -1139,44 +1199,29 @@ int JDBConn::ExecSQLcommand(char *sql)
/***********************************************************************/
int
JDBConn
::
Fetch
(
int
pos
)
{
jint
rc
;
jint
rc
=
JNI_ERR
;
PGLOBAL
&
g
=
m_G
;
if
(
m_Full
)
// Result set has one row
return
1
;
if
(
pos
)
{
if
(
!
m_Scrollable
)
{
strcpy
(
m_G
->
Message
,
"Cannot fetch(pos) if FORWARD ONLY"
);
return
-
1
;
}
else
if
(
fetchid
==
nullptr
)
{
fetchid
=
env
->
GetMethodID
(
jdi
,
"Fetch"
,
"(I)Z"
);
if
(
fetchid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot find method Fetch"
);
return
-
1
;
}
// endif fetchid
}
// endif's
strcpy
(
g
->
Message
,
"Cannot fetch(pos) if FORWARD ONLY"
);
return
rc
;
}
else
if
(
gmID
(
m_G
,
fetchid
,
"Fetch"
,
"(I)Z"
))
return
rc
;
if
(
env
->
CallBooleanMethod
(
job
,
fetchid
,
pos
))
rc
=
m_Rows
;
else
rc
=
-
1
;
}
else
{
if
(
readid
==
nullptr
)
{
readid
=
env
->
GetMethodID
(
jdi
,
"ReadNext"
,
"()I"
);
if
(
readid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot find method ReadNext"
);
return
-
1
;
}
// endif readid
}
// endif readid
if
(
gmID
(
g
,
readid
,
"ReadNext"
,
"()I"
))
return
rc
;
rc
=
env
->
CallBooleanMethod
(
job
,
readid
);
if
(
rc
>=
0
)
{
if
(
!
Check
(
rc
)
)
{
if
(
rc
==
0
)
m_Full
=
(
m_Fetch
==
1
);
else
...
...
@@ -1184,7 +1229,7 @@ int JDBConn::Fetch(int pos)
m_Rows
+=
(
int
)
rc
;
}
else
s
trcpy
(
m_G
->
Message
,
"Error fetching next row"
);
s
printf
(
g
->
Message
,
"Fetch: %s"
,
Msg
);
}
// endif pos
...
...
@@ -1201,15 +1246,8 @@ int JDBConn::Rewind(char *sql)
if
(
m_Full
)
rbuf
=
m_Rows
;
// No need to "rewind"
else
if
(
m_Scrollable
)
{
if
(
fetchid
==
nullptr
)
{
fetchid
=
env
->
GetMethodID
(
jdi
,
"Fetch"
,
"(I)Z"
);
if
(
fetchid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot find method Fetch"
);
if
(
gmID
(
m_G
,
fetchid
,
"Fetch"
,
"(I)Z"
))
return
-
1
;
}
// endif readid
}
// endif readid
jboolean
b
=
env
->
CallBooleanMethod
(
job
,
fetchid
,
0
);
...
...
@@ -1227,15 +1265,15 @@ void JDBConn::Close()
{
if
(
m_Opened
)
{
jint
rc
;
jmethodID
did
=
env
->
GetMethodID
(
jdi
,
"JdbcDisconnect"
,
"()I"
)
;
jmethodID
did
=
nullptr
;
if
(
did
==
nullptr
)
printf
(
"
ERROR: method JdbcDisconnect() not found !"
);
else
if
(
(
rc
=
env
->
CallIntMethod
(
job
,
did
)))
printf
(
"jdbcDisconnect:
rc=%d"
,
(
int
)
rc
);
if
(
gmID
(
m_G
,
did
,
"JdbcDisconnect"
,
"()I"
)
)
printf
(
"
%s
\n
"
,
Msg
);
else
if
(
Check
(
env
->
CallIntMethod
(
job
,
did
)))
printf
(
"jdbcDisconnect:
%s
\n
"
,
Msg
);
if
((
rc
=
jvm
->
DetachCurrentThread
()))
printf
(
"DetachCurrentThread: rc
= %d
"
,
(
int
)
rc
);
if
((
rc
=
jvm
->
DetachCurrentThread
())
!=
JNI_OK
)
printf
(
"DetachCurrentThread: rc
=%d
\n
"
,
(
int
)
rc
);
//rc = jvm->DestroyJavaVM();
m_Opened
=
false
;
...
...
@@ -1249,12 +1287,10 @@ void JDBConn::Close()
void
JDBConn
::
SetColumnValue
(
int
rank
,
PSZ
name
,
PVAL
val
)
{
PGLOBAL
&
g
=
m_G
;
char
*
msg
;
jint
ctyp
;
jlong
dtv
;
jstring
cn
,
jn
=
nullptr
;
jobject
dob
;
jmethodID
fldid
=
nullptr
;
if
(
rank
==
0
)
if
(
!
name
||
(
jn
=
env
->
NewStringUTF
(
name
))
==
nullptr
)
{
...
...
@@ -1262,10 +1298,11 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
longjmp
(
g
->
jumper
[
g
->
jump_level
],
TYPE_AM_JDBC
);
}
// endif name
// Returns 666 is case of error
ctyp
=
env
->
CallIntMethod
(
job
,
typid
,
rank
,
jn
);
if
(
(
msg
=
Check
()
))
{
sprintf
(
g
->
Message
,
"Getting ctyp: %s"
,
m
sg
);
if
(
Check
((
ctyp
==
666
)
?
-
1
:
1
))
{
sprintf
(
g
->
Message
,
"Getting ctyp: %s"
,
M
sg
);
longjmp
(
g
->
jumper
[
g
->
jump_level
],
TYPE_AM_JDBC
);
}
// endif Check
...
...
@@ -1273,11 +1310,8 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
case
12
:
// VARCHAR
case
-
1
:
// LONGVARCHAR
case
1
:
// CHAR
fldid
=
env
->
GetMethodID
(
jdi
,
"StringField"
,
"(ILjava/lang/String;)Ljava/lang/String;"
);
if
(
fldid
!=
nullptr
)
{
cn
=
(
jstring
)
env
->
CallObjectMethod
(
job
,
fldid
,
(
jint
)
rank
,
jn
);
if
(
!
gmID
(
g
,
chrfldid
,
"StringField"
,
"(ILjava/lang/String;)Ljava/lang/String;"
))
{
cn
=
(
jstring
)
env
->
CallObjectMethod
(
job
,
chrfldid
,
(
jint
)
rank
,
jn
);
if
(
cn
)
{
const
char
*
field
=
env
->
GetStringUTFChars
(
cn
,
(
jboolean
)
false
);
...
...
@@ -1294,30 +1328,25 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
case
4
:
// INTEGER
case
5
:
// SMALLINT
case
-
6
:
// TINYINT
fldid
=
env
->
GetMethodID
(
jdi
,
"IntField"
,
"(ILjava/lang/String;)I"
);
if
(
fldid
!=
nullptr
)
val
->
SetValue
((
int
)
env
->
CallIntMethod
(
job
,
fldid
,
rank
,
jn
));
if
(
!
gmID
(
g
,
intfldid
,
"IntField"
,
"(ILjava/lang/String;)I"
))
val
->
SetValue
((
int
)
env
->
CallIntMethod
(
job
,
intfldid
,
rank
,
jn
));
else
val
->
Reset
();
break
;
case
8
:
// DOUBLE
case
2
:
// NUMERIC
case
3
:
// DECIMAL
fldid
=
env
->
GetMethodID
(
jdi
,
"DoubleField"
,
"(ILjava/lang/String;)D"
);
if
(
fldid
!=
nullptr
)
val
->
SetValue
((
double
)
env
->
CallDoubleMethod
(
job
,
fldid
,
rank
,
jn
));
if
(
!
gmID
(
g
,
dblfldid
,
"DoubleField"
,
"(ILjava/lang/String;)D"
))
val
->
SetValue
((
double
)
env
->
CallDoubleMethod
(
job
,
dblfldid
,
rank
,
jn
));
else
val
->
Reset
();
break
;
case
7
:
// REAL
case
6
:
// FLOAT
fldid
=
env
->
GetMethodID
(
jdi
,
"FloatField"
,
"(ILjava/lang/String;)F"
);
if
(
fldid
!=
nullptr
)
val
->
SetValue
((
float
)
env
->
CallFloatMethod
(
job
,
fldid
,
rank
,
jn
));
if
(
!
gmID
(
g
,
fltfldid
,
"FloatField"
,
"(ILjava/lang/String;)F"
))
val
->
SetValue
((
float
)
env
->
CallFloatMethod
(
job
,
fltfldid
,
rank
,
jn
));
else
val
->
Reset
();
...
...
@@ -1325,11 +1354,9 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
case
91
:
// DATE
case
92
:
// TIME
case
93
:
// TIMESTAMP
fldid
=
env
->
GetMethodID
(
jdi
,
"TimestampField"
,
"(ILjava/lang/String;)Ljava/sql/Timestamp;"
);
if
(
fldid
!=
nullptr
)
{
dob
=
env
->
CallObjectMethod
(
job
,
fldid
,
(
jint
)
rank
,
jn
);
if
(
!
gmID
(
g
,
datfldid
,
"TimestampField"
,
"(ILjava/lang/String;)Ljava/sql/Timestamp;"
))
{
dob
=
env
->
CallObjectMethod
(
job
,
datfldid
,
(
jint
)
rank
,
jn
);
if
(
dob
)
{
jclass
jts
=
env
->
FindClass
(
"java/sql/Timestamp"
);
...
...
@@ -1355,10 +1382,8 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
break
;
case
-
5
:
// BIGINT
fldid
=
env
->
GetMethodID
(
jdi
,
"BigintField"
,
"(ILjava/lang/String;)J"
);
if
(
fldid
!=
nullptr
)
val
->
SetValue
((
long
long
)
env
->
CallLongMethod
(
job
,
fldid
,
(
jint
)
rank
,
jn
));
if
(
!
gmID
(
g
,
bigfldid
,
"BigintField"
,
"(ILjava/lang/String;)J"
))
val
->
SetValue
((
long
long
)
env
->
CallLongMethod
(
job
,
bigfldid
,
(
jint
)
rank
,
jn
));
else
val
->
Reset
();
...
...
@@ -1372,11 +1397,11 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
val
->
Reset
();
}
// endswitch Type
if
(
(
msg
=
Check
()
))
{
if
(
Check
(
))
{
if
(
rank
==
0
)
env
->
DeleteLocalRef
(
jn
);
sprintf
(
g
->
Message
,
"SetColumnValue: %s rank=%d ctyp=%d"
,
m
sg
,
rank
,
(
int
)
ctyp
);
sprintf
(
g
->
Message
,
"SetColumnValue: %s rank=%d ctyp=%d"
,
M
sg
,
rank
,
(
int
)
ctyp
);
longjmp
(
g
->
jumper
[
g
->
jump_level
],
TYPE_AM_JDBC
);
}
// endif Check
...
...
@@ -1390,21 +1415,22 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
/***********************************************************************/
bool
JDBConn
::
PrepareSQL
(
char
*
sql
)
{
if
(
prepid
==
nullptr
)
{
prepid
=
env
->
GetMethodID
(
jdi
,
"CreatePrepStmt"
,
"(Ljava/lang/String;)Z"
);
if
(
prepid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot find method CreatePrepStmt"
);
return
true
;
}
// endif prepid
}
// endif prepid
bool
b
=
true
;
PGLOBAL
&
g
=
m_G
;
if
(
!
gmID
(
g
,
prepid
,
"CreatePrepStmt"
,
"(Ljava/lang/String;)I"
))
{
// Create the prepared statement
jstring
qry
=
env
->
NewStringUTF
(
sql
);
jboolean
b
=
env
->
CallBooleanMethod
(
job
,
prepid
,
qry
);
if
(
Check
(
env
->
CallBooleanMethod
(
job
,
prepid
,
qry
)))
sprintf
(
g
->
Message
,
"CreatePrepStmt: %s"
,
Msg
);
else
b
=
false
;
env
->
DeleteLocalRef
(
qry
);
return
(
bool
)
b
;
}
// endif prepid
return
b
;
}
// end of PrepareSQL
/***********************************************************************/
...
...
@@ -1412,32 +1438,25 @@ bool JDBConn::PrepareSQL(char *sql)
/***********************************************************************/
int
JDBConn
::
ExecuteQuery
(
char
*
sql
)
{
int
rc
=
RC_FX
;
jint
ncol
;
jstring
qry
;
PGLOBAL
&
g
=
m_G
;
if
(
xqid
==
nullptr
)
{
// Get the methods used to execute a query and get the result
xqid
=
env
->
GetMethodID
(
jdi
,
"ExecuteQuery"
,
"(Ljava/lang/String;)I"
);
if
(
xqid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method ExecuteQuery"
);
return
RC_FX
;
}
// endif !xqid
}
// endif xqid
if
(
!
gmID
(
g
,
xqid
,
"ExecuteQuery"
,
"(Ljava/lang/String;)I"
))
{
qry
=
env
->
NewStringUTF
(
sql
);
ncol
=
env
->
CallIntMethod
(
job
,
xqid
,
qry
);
env
->
DeleteLocalRef
(
qry
);
if
(
ncol
<
0
)
{
sprintf
(
g
->
Message
,
"Error executing %s: ncol = %d"
,
sql
,
ncol
);
return
RC_FX
;
}
else
{
if
(
!
Check
(
ncol
))
{
m_Ncol
=
(
int
)
ncol
;
m_Aff
=
0
;
// Affected rows
}
// endif ncol
rc
=
RC_OK
;
}
else
sprintf
(
g
->
Message
,
"ExecuteQuery: %s"
,
Msg
);
env
->
DeleteLocalRef
(
qry
);
}
// endif xqid
return
RC_OK
;
}
// end of ExecuteQuery
...
...
@@ -1447,34 +1466,27 @@ int JDBConn::ExecuteQuery(char *sql)
/***********************************************************************/
int
JDBConn
::
ExecuteUpdate
(
char
*
sql
)
{
int
rc
=
RC_FX
;
jint
n
;
jstring
qry
;
PGLOBAL
&
g
=
m_G
;
if
(
xuid
==
nullptr
)
{
// Get the methods used to execute a query and get the affected rows
xuid
=
env
->
GetMethodID
(
jdi
,
"ExecuteUpdate"
,
"(Ljava/lang/String;)I"
);
if
(
xuid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method ExecuteUpdate"
);
return
RC_FX
;
}
// endif !xuid
}
// endif xuid
if
(
!
gmID
(
g
,
xuid
,
"ExecuteUpdate"
,
"(Ljava/lang/String;)I"
))
{
qry
=
env
->
NewStringUTF
(
sql
);
n
=
env
->
CallIntMethod
(
job
,
xuid
,
qry
);
env
->
DeleteLocalRef
(
qry
);
if
(
n
<
0
)
{
sprintf
(
g
->
Message
,
"Error executing %s: n = %d"
,
sql
,
n
);
return
RC_FX
;
}
else
{
if
(
!
Check
(
n
))
{
m_Ncol
=
0
;
m_Aff
=
(
int
)
n
;
// Affected rows
}
// endif n
rc
=
RC_OK
;
}
else
sprintf
(
g
->
Message
,
"ExecuteUpdate: %s n=%d"
,
Msg
,
n
);
return
RC_OK
;
env
->
DeleteLocalRef
(
qry
);
}
// endif xuid
return
rc
;
}
// end of ExecuteUpdate
/***********************************************************************/
...
...
@@ -1507,32 +1519,21 @@ int JDBConn::ExecuteSQL(void)
int
rc
=
RC_FX
;
PGLOBAL
&
g
=
m_G
;
if
(
xpid
==
nullptr
)
{
// Get the methods used to execute a prepared statement
xpid
=
env
->
GetMethodID
(
jdi
,
"ExecutePrep"
,
"()I"
);
if
(
xpid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method ExecutePrep"
);
return
rc
;
}
// endif xpid
}
// endif xpid
if
(
!
gmID
(
g
,
xpid
,
"ExecutePrep"
,
"()I"
))
{
jint
n
=
env
->
CallIntMethod
(
job
,
xpid
);
switch
((
int
)
n
)
{
case
-
1
:
case
-
2
:
strcpy
(
g
->
Message
,
"Exception error thrown while executing SQL"
);
break
;
case
-
3
:
if
(
n
==
-
3
)
strcpy
(
g
->
Message
,
"SQL statement is not prepared"
);
break
;
default:
else
if
(
Check
(
n
))
sprintf
(
g
->
Message
,
"ExecutePrep: %s"
,
Msg
);
else
{
m_Aff
=
(
int
)
n
;
rc
=
RC_OK
;
}
// endswitch n
}
// endif xpid
return
rc
;
}
// end of ExecuteSQL
...
...
@@ -1542,8 +1543,7 @@ int JDBConn::ExecuteSQL(void)
bool
JDBConn
::
SetParam
(
JDBCCOL
*
colp
)
{
PGLOBAL
&
g
=
m_G
;
char
*
msg
;
int
rc
=
false
;
bool
rc
=
false
;
PVAL
val
=
colp
->
GetValue
();
jint
n
,
i
=
(
jint
)
colp
->
GetRank
();
jshort
s
;
...
...
@@ -1557,58 +1557,38 @@ bool JDBConn::SetParam(JDBCCOL *colp)
switch
(
val
->
GetType
())
{
case
TYPE_STRING
:
setid
=
env
->
GetMethodID
(
jdi
,
"SetStringParm"
,
"(ILjava/lang/String;)V"
);
if
(
setid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot fing method SetStringParm"
);
if
(
gmID
(
g
,
setid
,
"SetStringParm"
,
"(ILjava/lang/String;)V"
))
return
true
;
}
// endif setid
jst
=
env
->
NewStringUTF
(
val
->
GetCharValue
());
env
->
CallVoidMethod
(
job
,
setid
,
i
,
jst
);
break
;
case
TYPE_INT
:
setid
=
env
->
GetMethodID
(
jdi
,
"SetIntParm"
,
"(II)V"
);
if
(
setid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot fing method SetIntParm"
);
if
(
gmID
(
g
,
setid
,
"SetIntParm"
,
"(II)V"
))
return
true
;
}
// endif setid
n
=
(
jint
)
val
->
GetIntValue
();
env
->
CallVoidMethod
(
job
,
setid
,
i
,
n
);
break
;
case
TYPE_TINY
:
case
TYPE_SHORT
:
setid
=
env
->
GetMethodID
(
jdi
,
"SetShortParm"
,
"(IS)V"
);
if
(
setid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot fing method SetShortParm"
);
if
(
gmID
(
g
,
setid
,
"SetShortParm"
,
"(IS)V"
))
return
true
;
}
// endif setid
s
=
(
jshort
)
val
->
GetShortValue
();
env
->
CallVoidMethod
(
job
,
setid
,
i
,
s
);
break
;
case
TYPE_BIGINT
:
setid
=
env
->
GetMethodID
(
jdi
,
"SetBigintParm"
,
"(IJ)V"
);
if
(
setid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot fing method SetBigintParm"
);
if
(
gmID
(
g
,
setid
,
"SetBigintParm"
,
"(IJ)V"
))
return
true
;
}
// endif setid
lg
=
(
jlong
)
val
->
GetBigintValue
();
env
->
CallVoidMethod
(
job
,
setid
,
i
,
lg
);
break
;
case
TYPE_DOUBLE
:
case
TYPE_DECIM
:
setid
=
env
->
GetMethodID
(
jdi
,
"SetDoubleParm"
,
"(ID)V"
);
if
(
setid
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method SetDoubleParm"
);
if
(
gmID
(
g
,
setid
,
"SetDoubleParm"
,
"(ID)V"
))
return
true
;
}
// endif setid
d
=
(
jdouble
)
val
->
GetFloatValue
();
env
->
CallVoidMethod
(
job
,
setid
,
i
,
d
);
...
...
@@ -1627,11 +1607,8 @@ bool JDBConn::SetParam(JDBCCOL *colp)
if
((
datobj
=
env
->
NewObject
(
dat
,
dtc
,
lg
))
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot make Timestamp object"
);
return
true
;
}
else
if
((
setid
=
env
->
GetMethodID
(
jdi
,
"SetTimestampParm"
,
"(ILjava/sql/Timestamp;)V"
))
==
nullptr
)
{
strcpy
(
g
->
Message
,
"Cannot find method SetTimestampParm"
);
}
else
if
(
gmID
(
g
,
setid
,
"SetTimestampParm"
,
"(ILjava/sql/Timestamp;)V"
))
return
true
;
}
// endif setid
env
->
CallVoidMethod
(
job
,
setid
,
i
,
datobj
);
break
;
...
...
@@ -1640,8 +1617,8 @@ bool JDBConn::SetParam(JDBCCOL *colp)
return
true
;
}
// endswitch Type
if
(
(
msg
=
Check
()
))
{
sprintf
(
g
->
Message
,
"SetParam: col=%s msg=%s"
,
colp
->
GetName
(),
m
sg
);
if
(
Check
(
))
{
sprintf
(
g
->
Message
,
"SetParam: col=%s msg=%s"
,
colp
->
GetName
(),
M
sg
);
rc
=
true
;
}
// endif msg
...
...
@@ -1707,14 +1684,10 @@ bool JDBConn::SetParam(JDBCCOL *colp)
int
i
,
n
,
size
;
PCOLRES
crp
;
jstring
js
;
jmethodID
gdid
=
env
->
GetMethodID
(
jdi
,
"GetDrivers"
,
"([Ljava/lang/String;I)I"
)
;
jmethodID
gdid
=
nullptr
;
if
(
env
->
ExceptionCheck
())
{
strcpy
(
m_G
->
Message
,
"ERROR: method GetDrivers() not found!"
);
env
->
ExceptionDescribe
();
env
->
ExceptionClear
();
if
(
gmID
(
m_G
,
gdid
,
"GetDrivers"
,
"([Ljava/lang/String;I)I"
))
return
true
;
}
// endif Check
// Build the java string array
jobjectArray
s
=
env
->
NewObjectArray
(
4
*
qrp
->
Maxres
,
...
...
@@ -1766,7 +1739,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
ushort
i
;
jint
*
n
=
nullptr
;
jstring
label
;
jmethodID
colid
;
jmethodID
colid
=
nullptr
;
int
rc
=
ExecSQLcommand
(
src
);
if
(
rc
==
RC_NF
)
{
...
...
@@ -1779,20 +1752,8 @@ bool JDBConn::SetParam(JDBCCOL *colp)
return
NULL
;
}
// endif's
colid
=
env
->
GetMethodID
(
jdi
,
"ColumnDesc"
,
"(I[I)Ljava/lang/String;"
);
if
(
colid
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"ERROR: method ColumnDesc() not found!"
);
return
NULL
;
}
// endif colid
// Build the java string array
jintArray
val
=
env
->
NewIntArray
(
4
);
if
(
val
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot allocate jint array"
);
if
(
gmID
(
g
,
colid
,
"ColumnDesc"
,
"(I[I)Ljava/lang/String;"
))
return
NULL
;
}
// endif colid
// Get max column name length
len
=
GetMaxValue
(
5
);
...
...
@@ -1813,11 +1774,28 @@ bool JDBConn::SetParam(JDBCCOL *colp)
case
5
:
crp
->
Name
=
"Nullable"
;
break
;
}
// endswitch i
// Build the java string array
jintArray
val
=
env
->
NewIntArray
(
4
);
if
(
val
==
nullptr
)
{
strcpy
(
m_G
->
Message
,
"Cannot allocate jint array"
);
return
NULL
;
}
// endif colid
/************************************************************************/
/* Now get the results into blocks. */
/************************************************************************/
for
(
i
=
0
;
i
<
m_Ncol
;
i
++
)
{
label
=
(
jstring
)
env
->
CallObjectMethod
(
job
,
colid
,
i
+
1
,
val
);
if
(
!
(
label
=
(
jstring
)
env
->
CallObjectMethod
(
job
,
colid
,
i
+
1
,
val
)))
{
if
(
Check
())
sprintf
(
g
->
Message
,
"ColumnDesc: %s"
,
Msg
);
else
strcpy
(
g
->
Message
,
"No result metadata"
);
env
->
ReleaseIntArrayElements
(
val
,
n
,
0
);
return
NULL
;
}
// endif label
name
=
env
->
GetStringUTFChars
(
label
,
(
jboolean
)
false
);
crp
=
qrp
->
Colresp
;
// Column_Name
crp
->
Kdata
->
SetValue
((
char
*
)
name
,
i
);
...
...
@@ -1835,7 +1813,6 @@ bool JDBConn::SetParam(JDBCCOL *colp)
/* Cleanup */
env
->
ReleaseIntArrayElements
(
val
,
n
,
0
);
Close
();
/************************************************************************/
/* Return the result pointer for use by GetData routines. */
...
...
@@ -1962,7 +1939,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
PVAL
*
pval
=
NULL
;
char
*
*
pbuf
=
NULL
;
jobjectArray
parms
;
jmethodID
catid
;
jmethodID
catid
=
nullptr
;
if
(
qrp
->
Maxres
<=
0
)
return
0
;
// 0-sized result"
...
...
@@ -2008,16 +1985,18 @@ bool JDBConn::SetParam(JDBCCOL *colp)
return
-
1
;
}
// endswitch infotype
catid
=
env
->
GetMethodID
(
jdi
,
fnc
,
"([Ljava/lang/String;)I"
);
if
(
catid
==
nullptr
)
{
sprintf
(
g
->
Message
,
"ERROR: method %s not found !"
,
fnc
);
if
(
gmID
(
g
,
catid
,
fnc
,
"([Ljava/lang/String;)I"
))
return
-
1
;
}
// endif maxid
// call method
ncol
=
env
->
CallIntMethod
(
job
,
catid
,
parms
);
if
(
Check
(
ncol
))
{
sprintf
(
g
->
Message
,
"%s: %s"
,
fnc
,
Msg
);
env
->
DeleteLocalRef
(
parms
);
return
-
1
;
}
// endif Check
// Not used anymore
env
->
DeleteLocalRef
(
parms
);
...
...
@@ -2061,13 +2040,15 @@ bool JDBConn::SetParam(JDBCCOL *colp)
// Now fetch the result
for
(
i
=
0
;
i
<
qrp
->
Maxres
;
i
++
)
{
if
((
rc
=
Fetch
(
0
))
==
0
)
{
if
(
Check
(
rc
=
Fetch
(
0
)))
{
sprintf
(
g
->
Message
,
"Fetch: %s"
,
Msg
);
return
-
1
;
}
if
(
rc
==
0
)
{
if
(
trace
)
htrc
(
"End of fetches i=%d
\n
"
,
i
);
break
;
}
else
if
(
rc
<
0
)
return
-
1
;
}
// endif rc
for
(
n
=
0
,
crp
=
qrp
->
Colresp
;
crp
;
n
++
,
crp
=
crp
->
Next
)
{
SetColumnValue
(
n
+
1
,
nullptr
,
pval
[
n
]);
...
...
storage/connect/jdbconn.h
View file @
c92f2606
...
...
@@ -53,6 +53,9 @@ typedef struct tagJCATPARM {
typedef
jint
(
JNICALL
*
CRTJVM
)
(
JavaVM
**
,
void
**
,
void
*
);
typedef
jint
(
JNICALL
*
GETJVM
)
(
JavaVM
**
,
jsize
,
jsize
*
);
#if defined(_DEBUG)
typedef
jint
(
JNICALL
*
GETDEF
)
(
void
*
);
#endif // _DEBUG
// JDBC connection to a data source
class
TDBJDBC
;
...
...
@@ -109,8 +112,15 @@ class JDBConn : public BLOCK {
public:
// Set static variables
static
void
SetJVM
(
void
)
{
LibJvm
=
NULL
;
CreateJavaVM
=
NULL
;
GetCreatedJavaVMs
=
NULL
;
}
static
void
SetJVM
(
void
)
{
LibJvm
=
NULL
;
CreateJavaVM
=
NULL
;
GetCreatedJavaVMs
=
NULL
;
#if defined(_DEBUG)
GetDefaultJavaVMInitArgs
=
NULL
;
#endif // _DEBUG
}
// end of SetJVM
static
void
ResetJVM
(
void
);
static
bool
GetJVM
(
PGLOBAL
g
);
...
...
@@ -120,7 +130,8 @@ class JDBConn : public BLOCK {
// JDBC operations
protected:
char
*
Check
(
void
);
bool
gmID
(
PGLOBAL
g
,
jmethodID
&
mid
,
const
char
*
name
,
const
char
*
sig
);
bool
Check
(
jint
rc
=
0
);
//void ThrowDJX(int rc, PSZ msg/*, HSTMT hstmt = SQL_NULL_HSTMT*/);
//void ThrowDJX(PSZ msg);
//void Free(void);
...
...
@@ -134,6 +145,9 @@ class JDBConn : public BLOCK {
#endif // !__WIN__
static
CRTJVM
CreateJavaVM
;
static
GETJVM
GetCreatedJavaVMs
;
#if defined(_DEBUG)
static
GETDEF
GetDefaultJavaVMInitArgs
;
#endif // _DEBUG
PGLOBAL
m_G
;
TDBJDBC
*
m_Tdb
;
JavaVM
*
jvm
;
// Pointer to the JVM (Java Virtual Machine)
...
...
@@ -150,9 +164,17 @@ class JDBConn : public BLOCK {
jmethodID
prepid
;
// The CreatePrepStmt method ID
jmethodID
xpid
;
// The ExecutePrep method ID
jmethodID
pcid
;
// The ClosePrepStmt method ID
jmethodID
errid
;
// The GetErrmsg method ID
jmethodID
chrfldid
;
// The StringField method ID
jmethodID
intfldid
;
// The IntField method ID
jmethodID
dblfldid
;
// The DoubleField method ID
jmethodID
fltfldid
;
// The FloatField method ID
jmethodID
datfldid
;
// The TimestampField method ID
jmethodID
bigfldid
;
// The BigintField method ID
//DWORD m_LoginTimeout;
//DWORD m_QueryTimeout;
//DWORD m_UpdateOptions;
char
*
Msg
;
char
m_IDQuoteChar
[
2
];
PSZ
m_Driver
;
PSZ
m_Url
;
...
...
storage/connect/tabjdbc.cpp
View file @
c92f2606
/************* TabJDBC C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABJDBC */
/* ------------- */
/* Version 1.
0
*/
/* Version 1.
1
*/
/* */
/* COPYRIGHT: */
/* ---------- */
...
...
@@ -34,8 +34,10 @@
/***********************************************************************/
/* Include relevant MariaDB header file. */
/***********************************************************************/
#define MYSQL_SERVER 1
#include "my_global.h"
#include "sql_class.h"
#include "sql_servers.h"
#if defined(__WIN__)
#include <io.h>
#include <fcntl.h>
...
...
@@ -67,7 +69,6 @@
#include "plgdbsem.h"
#include "mycat.h"
#include "xtable.h"
#include "jdbccat.h"
#include "tabjdbc.h"
#include "tabmul.h"
#include "reldef.h"
...
...
@@ -101,11 +102,107 @@ JDBCDEF::JDBCDEF(void)
Scrollable
=
Xsrc
=
false
;
}
// end of JDBCDEF constructor
/***********************************************************************/
/* Called on table construction. */
/***********************************************************************/
bool
JDBCDEF
::
SetParms
(
PJPARM
sjp
)
{
sjp
->
Url
=
Url
;
sjp
->
User
=
Username
;
sjp
->
Pwd
=
Password
;
return
true
;
}
// end of SetParms
/***********************************************************************/
/* Parse connection string */
/* */
/* SYNOPSIS */
/* ParseURL() */
/* Url The connection string to parse */
/* */
/* DESCRIPTION */
/* This is used to set the Url in case a wrapper server as been */
/* specified. This is rather experimental yet. */
/* */
/* RETURN VALUE */
/* RC_OK Url was a true URL */
/* RC_NF Url was a server name/table */
/* RC_FX Error */
/* */
/***********************************************************************/
int
JDBCDEF
::
ParseURL
(
PGLOBAL
g
,
char
*
url
,
bool
b
)
{
if
(
strncmp
(
url
,
"jdbc:"
,
5
))
{
// No "jdbc:" in connection string. Must be a straight
// "server" or "server/table"
// ok, so we do a little parsing, but not completely!
if
((
Tabname
=
strchr
(
url
,
'/'
)))
{
// If there is a single '/' in the connection string,
// this means the user is specifying a table name
*
Tabname
++=
'\0'
;
// there better not be any more '/'s !
if
(
strchr
(
Tabname
,
'/'
))
return
RC_FX
;
}
else
if
(
b
)
{
// Otherwise, straight server name,
Tabname
=
GetStringCatInfo
(
g
,
"Name"
,
NULL
);
Tabname
=
GetStringCatInfo
(
g
,
"Tabname"
,
Tabname
);
}
// endelse
if
(
trace
)
htrc
(
"server: %s Tabname: %s"
,
url
,
Tabname
);
// Now make the required URL
FOREIGN_SERVER
*
server
,
server_buffer
;
// get_server_by_name() clones the server if exists
if
(
!
(
server
=
get_server_by_name
(
current_thd
->
mem_root
,
url
,
&
server_buffer
)))
{
sprintf
(
g
->
Message
,
"Server %s does not exist!"
,
url
);
return
RC_FX
;
}
// endif server
if
(
strncmp
(
server
->
host
,
"jdbc:"
,
5
))
{
// Now make the required URL
Url
=
(
PSZ
)
PlugSubAlloc
(
g
,
NULL
,
0
);
strcat
(
strcpy
(
Url
,
"jdbc:"
),
server
->
scheme
);
strcat
(
strcat
(
Url
,
"://"
),
server
->
host
);
if
(
server
->
port
)
{
char
buf
[
16
];
sprintf
(
buf
,
"%d"
,
server
->
port
);
strcat
(
strcat
(
Url
,
":"
),
buf
);
}
// endif port
if
(
server
->
db
)
strcat
(
strcat
(
Url
,
"/"
),
server
->
db
);
PlugSubAlloc
(
g
,
NULL
,
strlen
(
Url
)
+
1
);
}
else
// host is a URL
Url
=
PlugDup
(
g
,
server
->
host
);
if
(
server
->
username
)
Username
=
PlugDup
(
g
,
server
->
username
);
if
(
server
->
password
)
Password
=
PlugDup
(
g
,
server
->
password
);
return
RC_NF
;
}
// endif
// Url was a JDBC URL, nothing to do
return
RC_OK
;
}
// end of ParseURL
/***********************************************************************/
/* DefineAM: define specific AM block values from JDBC file. */
/***********************************************************************/
bool
JDBCDEF
::
DefineAM
(
PGLOBAL
g
,
LPCSTR
am
,
int
poff
)
{
int
rc
=
RC_OK
;
Driver
=
GetStringCatInfo
(
g
,
"Driver"
,
NULL
);
Desc
=
Url
=
GetStringCatInfo
(
g
,
"Connect"
,
NULL
);
...
...
@@ -120,28 +217,33 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
}
// endif Connect
if
(
Url
)
rc
=
ParseURL
(
g
,
Url
);
if
(
rc
==
RC_FX
)
// Error
return
true
;
else
if
(
rc
==
RC_OK
)
{
// Url was not a server name
Tabname
=
GetStringCatInfo
(
g
,
"Name"
,
(
Catfunc
&
(
FNC_TABLE
|
FNC_COL
))
?
NULL
:
Name
);
Tabname
=
GetStringCatInfo
(
g
,
"Tabname"
,
Tabname
);
Tabschema
=
GetStringCatInfo
(
g
,
"Dbname"
,
NULL
);
Tabschema
=
GetStringCatInfo
(
g
,
"Schema"
,
Tabschema
);
Tabcat
=
GetStringCatInfo
(
g
,
"Qualifier"
,
NULL
);
Tabcat
=
GetStringCatInfo
(
g
,
"Catalog"
,
Tabcat
);
Tabtype
=
GetStringCatInfo
(
g
,
"Tabtype"
,
NULL
);
Username
=
GetStringCatInfo
(
g
,
"User"
,
NULL
);
Password
=
GetStringCatInfo
(
g
,
"Password"
,
NULL
);
}
// endif rc
if
((
Srcdef
=
GetStringCatInfo
(
g
,
"Srcdef"
,
NULL
)))
Read_Only
=
true
;
Tabcat
=
GetStringCatInfo
(
g
,
"Qualifier"
,
NULL
);
Tabcat
=
GetStringCatInfo
(
g
,
"Catalog"
,
Tabcat
);
Tabschema
=
GetStringCatInfo
(
g
,
"Dbname"
,
NULL
);
Tabschema
=
GetStringCatInfo
(
g
,
"Schema"
,
Tabschema
);
Tabtype
=
GetStringCatInfo
(
g
,
"Tabtype"
,
NULL
);
Qrystr
=
GetStringCatInfo
(
g
,
"Query_String"
,
"?"
);
Sep
=
GetStringCatInfo
(
g
,
"Separator"
,
NULL
);
Xsrc
=
GetBoolCatInfo
(
"Execsrc"
,
FALSE
);
Maxerr
=
GetIntCatInfo
(
"Maxerr"
,
0
);
Maxres
=
GetIntCatInfo
(
"Maxres"
,
0
);
Quoted
=
GetIntCatInfo
(
"Quoted"
,
0
);
//Options = JDBConn::noJDBCDialog;
//Options = JDBConn::noJDBCDialog | JDBConn::useCursorLib;
//Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT);
//Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT);
Scrollable
=
GetBoolCatInfo
(
"Scrollable"
,
false
);
...
...
@@ -274,6 +376,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Ncol
=
0
;
Nparm
=
0
;
Placed
=
false
;
Prepared
=
false
;
Werr
=
false
;
Rerr
=
false
;
Ops
.
Fsize
=
Ops
.
CheckSize
(
Rows
);
...
...
storage/connect/tabjdbc.h
View file @
c92f2606
...
...
@@ -7,6 +7,7 @@
/***********************************************************************/
#include "colblk.h"
#include "resource.h"
#include "jdbccat.h"
typedef
class
JDBCDEF
*
PJDBCDEF
;
typedef
class
TDBJDBC
*
PTDBJDBC
;
...
...
@@ -44,6 +45,8 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
virtual
int
Indexable
(
void
)
{
return
2
;
}
virtual
bool
DefineAM
(
PGLOBAL
g
,
LPCSTR
am
,
int
poff
);
virtual
PTDB
GetTable
(
PGLOBAL
g
,
MODE
m
);
int
ParseURL
(
PGLOBAL
g
,
char
*
url
,
bool
b
=
true
);
bool
SetParms
(
PJPARM
sjp
);
protected:
// Members
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment