public static void TestWkbImportOnPostgresST() { try { java.sql.Connection con = java.sql.DriverManager.GetConnection("jdbc:postgresql://tb.esri.com:5432/new_gdb", "tb", "tb"); com.epl.geometry.OperatorFactoryLocal factory = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorImportFromWkb operatorImport = (com.epl.geometry.OperatorImportFromWkb)factory.GetOperator(com.epl.geometry.Operator.Type.ImportFromWkb); string stmt = "SELECT objectid,sde.st_asbinary(shape) FROM new_gdb.tb.interstates a WHERE objectid IN (2) AND (a.shape IS NULL OR sde.st_geometrytype(shape)::text IN ('ST_MULTILINESTRING','ST_LINESTRING')) LIMIT 1000"; java.sql.PreparedStatement ps = con.PrepareStatement(stmt); java.sql.ResultSet rs = ps.ExecuteQuery(); while (rs.Next()) { byte[] rsWkbGeom = rs.GetBytes(2); com.epl.geometry.Geometry geomBorg = null; if (rsWkbGeom != null) { geomBorg = operatorImport.Execute(0, com.epl.geometry.Geometry.Type.Unknown, System.IO.MemoryStream.Wrap(rsWkbGeom), null); } } ps.Close(); con.Close(); } catch (System.Exception) { } }
/// <summary> /// Writes specified output to table in database </summary> /// <param name="output"> </param> public virtual void writeOutput(double[] output) { try { string sql = "INSERT " + tableName + " VALUES("; for (int i = 0; i < output.Length; i++) { sql += "?"; if (i < (output.Length - 1)) // add coma if not last { sql = ", "; } } sql += ")"; // for (int i = 0; i < output.length; i++) { // sql += output[i]; // if (i < (output.length - 1)) { // sql = ", "; // } // } // Statement stmt = connection.createStatement(); java.sql.PreparedStatement stmt = connection.prepareStatement(sql); for (int i = 0; i < output.Length; i++) { stmt.setDouble(i, output[i]); } stmt.executeUpdate(sql); stmt.close(); } catch (java.sql.SQLException ex) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new NeurophInputException("Error executing query at JDBCOutputAdapter", ex); } }
private void InternalCreateStatement() { // Z:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQLCLRInsert\Program.cs // X:\jsc.svn\examples\java\appengine\Test\TestThreadManager\TestThreadManager\ApplicationWebService.cs //throw null; // tested by? if (this.InternalStatement != null) { return; } var sql = this.InternalCommandText; //Console.WriteLine("enter InternalCreateStatement" + new { sql }); try { // http://www.javaworld.com/javaworld/jw-04-2007/jw-04-jdbc.html if (this.Parameters.InternalParameters.Count > 0) { //Console.WriteLine("we have InternalParameters for " + sql); var parameters = this.Parameters.InternalParameters; var index = from p in parameters from i in this.CommandText.GetIndecies(p.ParameterName) orderby i select new { p, i }; // did we break it? foreach (var p in parameters.ToArray()) { // java seems to like indexed parameters instead sql = sql.Replace(p.ParameterName, "?"); } this.InternalPreparedStatement = this.c.InternalConnection.prepareStatement(sql); var c = 0; foreach (var item in index) { c++; // X:\jsc.svn\examples\java\appengine\Test\TestThreadManager\TestThreadManager\ApplicationWebService.cs // Z:\jsc.svn\examples\java\Test\TestIsinst\TestIsinst\Class1.cs if (item.p.Value == null) { this.InternalPreparedStatement.setObject(c, null); } else if (item.p.Value is int) { this.InternalPreparedStatement.setInt(c, (int)item.p.Value); } else if (item.p.Value is long) { this.InternalPreparedStatement.setLong(c, (long)item.p.Value); } else if (item.p.Value is double) { // X:\jsc.svn\examples\javascript\forms\Test\TestSQLiteGroupBy\TestSQLiteGroupBy\ApplicationWebService.cs this.InternalPreparedStatement.setDouble(c, (double)item.p.Value); } else if (item.p.Value is string) { this.InternalPreparedStatement.setString(c, (string)item.p.Value); } else if (item.p.Value is byte[]) { this.InternalPreparedStatement.setBytes(c, (sbyte[])item.p.Value); } else { //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? { CommandText = insert into Table1 (ContentValue, ContentBytes) values (@ContentValue /* text */, @ContentBytes), type = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter, isBytes = true, bytes = [B, eqBytes = true, item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@1908330, i = 82 } } // http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#setBytes(int, byte[]) //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? // { CommandText = insert into Table1 (ContentValue, ContentBytes) values (@ContentValue /* text */, @ContentBytes), // item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@47f703, i = 82 }, // type = __AnonymousTypes__ScriptCoreLibJava.__f__AnonymousType1_2 } //var isBytes = item.p.Value is byte[]; //var bytes = typeof(byte[]); //var eqBytes = item.p.Value.GetType() == bytes; // double? //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? { CommandText = insert into `Book1.Middle` (`Title`, `Ratio`, `FooStateEnum`, `GooStateEnum`, `x`, `Tag`, `Timestamp`) values (@Title, @Ratio, @FooStateEnum, @GooStateEnum, @x, @Tag, @Timestamp), type = java.lang.Double, item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@1dc5180, i = 120 } } // at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteCommand.InternalCreateStatement(__SQLiteCommand.java:225) // ... 89 more var message = "InternalCreateStatement, what to do with this? " + new { this.CommandText, type = item.p.Value.GetType(), //isBytes, //bytes, //eqBytes, item, }; throw new InvalidOperationException(message); } } // add values this.InternalStatement = this.InternalPreparedStatement; } if (this.InternalStatement == null) { this.InternalStatement = this.c.InternalConnection.createStatement(); } } catch { throw; } //try //{ // // Caused by: java.lang.RuntimeException: GetFieldType fault: { ColumnType = 3, ordinal = 0, CommandText = select sum(`Deposit`) // // at ScriptCoreLib.Shared.Data.Diagnostics.QueryStrategyExtensions.Sum(QueryStrategyExtensions.java:124) // //from `Book18.Sheet2` // Console.WriteLine("\n__SQLiteCommand.InternalCreateStatement " + new // { // //CurrentThreadID = Thread.CurrentThread.ManagedThreadId, // //CurrentThreadHashCode = Thread.CurrentThread.GetHashCode(), // sql, // //isReadOnly = this.c.InternalConnection.isReadOnly(), // // If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation. // //isValid = this.c.InternalConnection.isValid(0) // }); //} //catch //{ //} }
private void InternalCreateStatement() { // Z:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQLCLRInsert\Program.cs // X:\jsc.svn\examples\java\appengine\Test\TestThreadManager\TestThreadManager\ApplicationWebService.cs //throw null; // tested by? if (this.InternalStatement != null) return; var sql = this.InternalCommandText; //Console.WriteLine("enter InternalCreateStatement" + new { sql }); try { // http://www.javaworld.com/javaworld/jw-04-2007/jw-04-jdbc.html if (this.Parameters.InternalParameters.Count > 0) { //Console.WriteLine("we have InternalParameters for " + sql); var parameters = this.Parameters.InternalParameters; var index = from p in parameters from i in this.CommandText.GetIndecies(p.ParameterName) orderby i select new { p, i }; // did we break it? foreach (var p in parameters.ToArray()) { // java seems to like indexed parameters instead sql = sql.Replace(p.ParameterName, "?"); } this.InternalPreparedStatement = this.c.InternalConnection.prepareStatement(sql); var c = 0; foreach (var item in index) { c++; // X:\jsc.svn\examples\java\appengine\Test\TestThreadManager\TestThreadManager\ApplicationWebService.cs // Z:\jsc.svn\examples\java\Test\TestIsinst\TestIsinst\Class1.cs if (item.p.Value == null) { this.InternalPreparedStatement.setObject(c, null); } else if (item.p.Value is int) this.InternalPreparedStatement.setInt(c, (int)item.p.Value); else if (item.p.Value is long) this.InternalPreparedStatement.setLong(c, (long)item.p.Value); else if (item.p.Value is double) // X:\jsc.svn\examples\javascript\forms\Test\TestSQLiteGroupBy\TestSQLiteGroupBy\ApplicationWebService.cs this.InternalPreparedStatement.setDouble(c, (double)item.p.Value); else if (item.p.Value is string) this.InternalPreparedStatement.setString(c, (string)item.p.Value); else if (item.p.Value is byte[]) this.InternalPreparedStatement.setBytes(c, (sbyte[])item.p.Value); else { //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? { CommandText = insert into Table1 (ContentValue, ContentBytes) values (@ContentValue /* text */, @ContentBytes), type = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter, isBytes = true, bytes = [B, eqBytes = true, item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@1908330, i = 82 } } // http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#setBytes(int, byte[]) //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? // { CommandText = insert into Table1 (ContentValue, ContentBytes) values (@ContentValue /* text */, @ContentBytes), // item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@47f703, i = 82 }, // type = __AnonymousTypes__ScriptCoreLibJava.__f__AnonymousType1_2 } //var isBytes = item.p.Value is byte[]; //var bytes = typeof(byte[]); //var eqBytes = item.p.Value.GetType() == bytes; // double? //Caused by: java.lang.RuntimeException: InternalCreateStatement, what to do with this? { CommandText = insert into `Book1.Middle` (`Title`, `Ratio`, `FooStateEnum`, `GooStateEnum`, `x`, `Tag`, `Timestamp`) values (@Title, @Ratio, @FooStateEnum, @GooStateEnum, @x, @Tag, @Timestamp), type = java.lang.Double, item = { p = ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteParameter@1dc5180, i = 120 } } // at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteCommand.InternalCreateStatement(__SQLiteCommand.java:225) // ... 89 more var message = "InternalCreateStatement, what to do with this? " + new { this.CommandText, type = item.p.Value.GetType(), //isBytes, //bytes, //eqBytes, item, }; throw new InvalidOperationException(message); } } // add values this.InternalStatement = this.InternalPreparedStatement; } if (this.InternalStatement == null) this.InternalStatement = this.c.InternalConnection.createStatement(); } catch { throw; } //try //{ // // Caused by: java.lang.RuntimeException: GetFieldType fault: { ColumnType = 3, ordinal = 0, CommandText = select sum(`Deposit`) // // at ScriptCoreLib.Shared.Data.Diagnostics.QueryStrategyExtensions.Sum(QueryStrategyExtensions.java:124) // //from `Book18.Sheet2` // Console.WriteLine("\n__SQLiteCommand.InternalCreateStatement " + new // { // //CurrentThreadID = Thread.CurrentThread.ManagedThreadId, // //CurrentThreadHashCode = Thread.CurrentThread.GetHashCode(), // sql, // //isReadOnly = this.c.InternalConnection.isReadOnly(), // // If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation. // //isValid = this.c.InternalConnection.isValid(0) // }); //} //catch //{ //} }
public OraclePreparedStatement(java.sql.PreparedStatement statement) : base(statement) { _info = Wrapped.GetType().GetMethod("setFixedCHAR"); }