Mercurial > hg > monetdb-java
comparison tests/JDBC_API_Tester.java @ 764:052c23fbfab2
Corrected implementation of Connection methods getClientInfo() and setClientInfo().
They used to get/set Connection properties instead of Client Info properties which was a incorrect.
MonetDB does not support Client Info properties.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 05 Jul 2023 21:34:11 +0200 (22 months ago) |
parents | 7f68120de37c |
children | b6d113ee35ae |
comparison
equal
deleted
inserted
replaced
763:e8afd7de2538 | 764:052c23fbfab2 |
---|---|
108 jt.Bug_PrepStmtSetObject_CLOB_6349(); | 108 jt.Bug_PrepStmtSetObject_CLOB_6349(); |
109 jt.Bug_PrepStmtSetString_6382(); | 109 jt.Bug_PrepStmtSetString_6382(); |
110 jt.Bug_PrepStmt_With_Errors_Jira292(); | 110 jt.Bug_PrepStmt_With_Errors_Jira292(); |
111 jt.BugResultSetMetaData_Bug_6183(); | 111 jt.BugResultSetMetaData_Bug_6183(); |
112 jt.BugSetQueryTimeout_Bug_3357(); | 112 jt.BugSetQueryTimeout_Bug_3357(); |
113 jt.SQLcopyinto(); | 113 jt.SQLcopyinto(con_URL); |
114 jt.DecimalPrecisionAndScale(); | 114 jt.DecimalPrecisionAndScale(); |
115 | 115 |
116 /* run next long running test (11 minutes) only before a new release */ | 116 /* run next long running test (11 minutes) only before a new release */ |
117 /* jt.Test_PSlargeamount(); */ | 117 /* jt.Test_PSlargeamount(); */ |
118 | 118 |
6620 * in performing COPY INTO ... FROM STDIN sequences. | 6620 * in performing COPY INTO ... FROM STDIN sequences. |
6621 * It shows how a data stream via MapiSocket to STDIN can be performed. | 6621 * It shows how a data stream via MapiSocket to STDIN can be performed. |
6622 * | 6622 * |
6623 * @author Fabian Groffen, Martin van Dinther | 6623 * @author Fabian Groffen, Martin van Dinther |
6624 */ | 6624 */ |
6625 private void SQLcopyinto() { | 6625 private void SQLcopyinto(final String conn_URL) { |
6626 sb.setLength(0); // clear the output log buffer | 6626 sb.setLength(0); // clear the output log buffer |
6627 | 6627 |
6628 final String tablenm = "exampleSQLCopyInto"; | 6628 final String tablenm = "exampleSQLCopyInto"; |
6629 Statement stmt = null; | 6629 Statement stmt = null; |
6630 ResultSet rs = null; | 6630 ResultSet rs = null; |
6631 try { | 6631 try { |
6632 stmt = con.createStatement(); | 6632 stmt = con.createStatement(); |
6633 stmt.execute("CREATE TABLE IF NOT EXISTS " + tablenm + " (id int, val varchar(24))"); | 6633 stmt.execute("CREATE TABLE IF NOT EXISTS " + tablenm + " (id int, val varchar(24))"); |
6634 | 6634 |
6635 fillTableUsingCopyIntoSTDIN(tablenm); | 6635 fillTableUsingCopyIntoSTDIN(conn_URL, tablenm); |
6636 | 6636 |
6637 // check content of the table populated via COPY INTO ... FROM STDIN | 6637 // check content of the table populated via COPY INTO ... FROM STDIN |
6638 sb.append("Listing uploaded data:\n"); | 6638 sb.append("Listing uploaded data:\n"); |
6639 int row = 0; | 6639 int row = 0; |
6640 rs = stmt.executeQuery("SELECT * FROM " + tablenm); | 6640 rs = stmt.executeQuery("SELECT * FROM " + tablenm); |
6680 "Row data: 7999, val_7999\n" + | 6680 "Row data: 7999, val_7999\n" + |
6681 "Row data: 8999, val_8999\n" + | 6681 "Row data: 8999, val_8999\n" + |
6682 "SQLcopyinto completed\n"); | 6682 "SQLcopyinto completed\n"); |
6683 } | 6683 } |
6684 | 6684 |
6685 private void fillTableUsingCopyIntoSTDIN(String tablenm) throws Exception { | 6685 private void fillTableUsingCopyIntoSTDIN(final String conn_URL, final String tablenm) throws Exception { |
6686 sb.append("CopyInto STDIN begin\n"); | 6686 sb.append("CopyInto STDIN begin\n"); |
6687 | 6687 |
6688 org.monetdb.mcl.net.MapiSocket server = new org.monetdb.mcl.net.MapiSocket(); | 6688 org.monetdb.mcl.net.MapiSocket server = new org.monetdb.mcl.net.MapiSocket(); |
6689 try { | 6689 try { |
6690 server.setLanguage("sql"); | 6690 server.setLanguage("sql"); |
6691 | 6691 |
6692 // extract from MonetConnection object the used connection properties | 6692 // extract from conn_URL the used connection properties |
6693 String host = con.getClientInfo("host"); | 6693 String host = extractFromJDBCURL(conn_URL, "host"); |
6694 int port = Integer.parseInt(con.getClientInfo("port")); | 6694 int port = Integer.parseInt(extractFromJDBCURL(conn_URL, "port")); |
6695 String login = con.getClientInfo("user"); | 6695 String login = extractFromJDBCURL(conn_URL, "user"); |
6696 String passw = con.getClientInfo("password"); | 6696 String passw = extractFromJDBCURL(conn_URL, "password"); |
6697 | 6697 String database = extractFromJDBCURL(conn_URL, "database"); |
6698 String database = con.getClientInfo("database"); | 6698 // sb.append("conn_URL: " + conn_URL + "\n"); |
6699 // sb.append("host: " + host + " port: " + port + " dbname: " + database + " login: " + login + " passwd: " + passw + "\n"); | |
6700 | |
6701 sb.append("Before connecting to MonetDB server via MapiSocket\n"); | |
6699 server.setDatabase(database); | 6702 server.setDatabase(database); |
6700 | |
6701 // sb.append("host: " + host + " port: " + port + " login: " + login + " passwd: " + passw + "\n"); | |
6702 sb.append("Before connecting to MonetDB server via MapiSocket\n"); | |
6703 List<String> warning = server.connect(host, port, login, passw); | 6703 List<String> warning = server.connect(host, port, login, passw); |
6704 if (warning != null) { | 6704 if (warning != null) { |
6705 for (Iterator<String> it = warning.iterator(); it.hasNext(); ) { | 6705 for (Iterator<String> it = warning.iterator(); it.hasNext(); ) { |
6706 sb.append("Warning: ").append(it.next().toString()).append("\n"); | 6706 sb.append("Warning: ").append(it.next().toString()).append("\n"); |
6707 } | 6707 } |
6746 // close MAPI connection to MonetDB server | 6746 // close MAPI connection to MonetDB server |
6747 server.close(); | 6747 server.close(); |
6748 } | 6748 } |
6749 | 6749 |
6750 sb.append("CopyInto STDIN end\n"); | 6750 sb.append("CopyInto STDIN end\n"); |
6751 } | |
6752 | |
6753 private String extractFromJDBCURL(String conn_URL, String prop) { | |
6754 // URL="jdbc:monetdb://${HOST}:${MAPIPORT}/${DBNAME}?user=$(USER)&password=$(PWD)&${JDBC_EXTRA_ARGS}" | |
6755 // URL example: jdbc:monetdb://localhost:35145/mTests_sql_jdbc_tests?user=monetdb&password=monetdb | |
6756 final String pre = "jdbc:monetdb://"; | |
6757 final int pre_len = pre.length(); | |
6758 int start = 0, end = 0; | |
6759 if ("host".equals(prop)) { | |
6760 start = conn_URL.indexOf(pre); | |
6761 if (start >= 0) { | |
6762 start += pre_len; | |
6763 end = conn_URL.indexOf(':', start); | |
6764 } | |
6765 } else | |
6766 if ("port".equals(prop)) { | |
6767 start = conn_URL.indexOf(':', pre_len); | |
6768 if (start >= 0) { | |
6769 start += 1; | |
6770 end = conn_URL.indexOf('/', start); | |
6771 } | |
6772 } else | |
6773 if ("database".equals(prop)) { | |
6774 start = conn_URL.indexOf('/', pre_len + 1); | |
6775 if (start >= 0) { | |
6776 start += 1; | |
6777 end = conn_URL.indexOf('?', start); | |
6778 } | |
6779 } else | |
6780 if ("user".equals(prop)) { | |
6781 start = conn_URL.indexOf("user=", pre_len); | |
6782 if (start >= 0) { | |
6783 start += 5; | |
6784 end = conn_URL.indexOf('&', start); | |
6785 } | |
6786 } else | |
6787 if ("password".equals(prop)) { | |
6788 start = conn_URL.indexOf("password=", pre_len); | |
6789 if (start >= 0) { | |
6790 start += 9; | |
6791 end = conn_URL.indexOf('&', start); | |
6792 } | |
6793 } | |
6794 if (start >= pre_len) { | |
6795 if (end < 0) | |
6796 end = conn_URL.length(); | |
6797 if (end > start) | |
6798 return conn_URL.substring(start, end); | |
6799 } | |
6800 return ""; | |
6751 } | 6801 } |
6752 | 6802 |
6753 private void DecimalPrecisionAndScale() { | 6803 private void DecimalPrecisionAndScale() { |
6754 sb.setLength(0); // clear the output log buffer | 6804 sb.setLength(0); // clear the output log buffer |
6755 | 6805 |