public override void Close()
        {
            //Console.WriteLine("__SQLiteConnection.Close");

            try
            {
                if (this.InternalConnection != null)
                {
                    this.InternalConnection.close();
                    this.InternalConnection = null;
                }
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        public override void ChangeDatabase(String database)
        {
            IsConnecting = true;
            try {
                ClearReferences();
                java.sql.Connection con = JdbcConnection;
                con.setCatalog(database);
//				ConnectionStringHelper.UpdateValue(UserParameters,StringManager.GetStringArray("CON_DATABASE"),database);
            }
            catch (SQLWarning warning) {
                OnSqlWarning(warning);
            }
            catch (SQLException exp) {
                throw CreateException(exp);
            }
            finally {
                IsConnecting = false;
            }
        }
        public override void Open()
        {
            // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectGroupByAndConstant\TestSelectGroupByAndConstant\ApplicationWebService.cs
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201403/20140322

            // 39ms __SQLiteConnection ctor { connectionstring = Data Source=file:StressData.s3db }

            //Console.WriteLine("__SQLiteConnection.Open");

            try
            {
                var x = new
                {
                    this.InternalConnectionString.Server,
                    this.InternalConnectionString.UserID,
                    this.InternalConnectionString.Password,
                };

                //                { InternalInstanceName = instance_name, InternalUser = user1, Password =  }
                //Dec 24, 2012 9:25:59 AM com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver openConnection
                //SEVERE: Could not allocate a connection
                //java.sql.SQLException: Access denied for user 'user1'@'localhost' (using password: NO)
                //        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
                //        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)

                //Console.WriteLine(x.ToString());

                // Caused by: java.sql.SQLException: No suitable driver found for jdbc:google:rdbms://instance_name

                //java.lang.RuntimeException: __SQLiteConnection { Message = Access denied for user 'user3'@'localhost' (using password: NO), StackTrace = java.sql.SQLException: Access denied for user 'user3'@'localhost' (using password: NO)
                //   at com.google.cloud.sql.jdbc.internal.Exceptions.newSqlException(Exceptions.java:219)
                //   at com.google.cloud.sql.jdbc.internal.SqlProtoClient.check(SqlProtoClient.java:158)
                //   at com.google.cloud.sql.jdbc.internal.SqlProtoClient.openConnection(SqlProtoClient.java:60)
                //   at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:66)
                //   at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:26)
                //   at java.sql.DriverManager.getConnection(Unknown Source)
                //   at java.sql.DriverManager.getConnection(Unknown Source)
                //   at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteConnection.Open(__SQLiteConnection.java:66)


                // https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/Vm5PTq4_0lg
                // Instance == Your Google API Project ID:InstanceName

                this.InternalConnection = DriverManager.getConnection(
                    OpenConnectionPrefix + x.Server,
                    x.UserID,
                    x.Password
                    );
            }
            catch (Exception ex)
            {
                //        Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
                //at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteConnection.Open(__SQLiteConnection.java:39)
                //at ScriptCoreLib.Shared.Data.Diagnostics.WithConnectionLambda___c__DisplayClass2._WithConnection_b__1(WithConnectionLambda___c__DisplayClass2.java:36)

                if (ex.Message != null)
                {
                    if (ex.Message.Contains("com.mysql.jdbc.Driver"))
                    {
                        // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAppEngineOrderByThenGroupBy\ApplicationWebService.cs

                        // "C:\util\appengine-java-sdk-1.9.2\lib\impl\mysql-connector-java-5.1.30-bin.jar"
                        // "C:\util\appengine-java-sdk-1.8.8\lib\impl\mysql-connector-java-5.1.22-bin.jar"
                        // "C:\util\appengine-java-sdk-1.9.9\lib\impl\mysql-connector-java-5.1.30-bin.jar"

                        // http://dev.mysql.com/downloads/connector/j/

                        Console.WriteLine(
                            @"!!! did you set up the mysql jar? check C:\util\appengine-java-sdk-1.9.9\lib\impl\mysql-connector-java-5.1.30-bin.jar"
                            );
                    }
                }

                //                C:\Program Files (x86)\Java\jdk1.7.0_45\bin\javac.exe  -encoding UTF-8 -cp Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\release;C:\util\appengine-java-sdk-1.8.8\lib\impl\*;C:\util\appengine-java-sdk-1.8.8\lib\shared\* -d "Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\release" @"Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\files"

                //Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\java\ScriptCoreLibJava\BCLImplementation\System\Data\SQLite\__SQLiteConnection.java:47: error: unreported exception SQLException; must be caught or declared to be thrown
                //            throw exception1;
                //            ^
                //Note: Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\java\ScriptCoreLibJava\BCLImplementation\System\Threading\__Thread.java uses or overrides a deprecated API.

                throw new InvalidOperationException("__SQLiteConnection " + new { ex.Message, ex.StackTrace });
            }

            // to be done by the user?
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAppEngineOrderByThenGroupBy\ApplicationWebService.cs


            //using (var cmd = new __SQLiteCommand(
            //    "CREATE DATABASE IF NOT EXISTS `" + this.InternalConnectionString.DataSource + "`",
            //    (__SQLiteConnection)(object)this))
            //{
            //    cmd.ExecuteNonQuery();
            //}


            //// http://stackoverflow.com/questions/1675333/php-mysql-joins-across-databases
            //using (var cmd = new __SQLiteCommand(
            //    "USE `" + this.InternalConnectionString.DataSource + "`",
            //    (__SQLiteConnection)(object)this))
            //{
            //    cmd.ExecuteNonQuery();
            //}
        }
        public override void Open()
        {
            // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectGroupByAndConstant\TestSelectGroupByAndConstant\ApplicationWebService.cs
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201403/20140322

            // 39ms __SQLiteConnection ctor { connectionstring = Data Source=file:StressData.s3db }

            //Console.WriteLine("__SQLiteConnection.Open");

            try
            {
                var x = new
                {
                    this.InternalConnectionString.Server,
                    this.InternalConnectionString.UserID,
                    this.InternalConnectionString.Password,
                };

                //                { InternalInstanceName = instance_name, InternalUser = user1, Password =  }
                //Dec 24, 2012 9:25:59 AM com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver openConnection
                //SEVERE: Could not allocate a connection
                //java.sql.SQLException: Access denied for user 'user1'@'localhost' (using password: NO)
                //        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
                //        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)

                //Console.WriteLine(x.ToString());

                // Caused by: java.sql.SQLException: No suitable driver found for jdbc:google:rdbms://instance_name

                //java.lang.RuntimeException: __SQLiteConnection { Message = Access denied for user 'user3'@'localhost' (using password: NO), StackTrace = java.sql.SQLException: Access denied for user 'user3'@'localhost' (using password: NO)
                //   at com.google.cloud.sql.jdbc.internal.Exceptions.newSqlException(Exceptions.java:219)
                //   at com.google.cloud.sql.jdbc.internal.SqlProtoClient.check(SqlProtoClient.java:158)
                //   at com.google.cloud.sql.jdbc.internal.SqlProtoClient.openConnection(SqlProtoClient.java:60)
                //   at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:66)
                //   at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:26)
                //   at java.sql.DriverManager.getConnection(Unknown Source)
                //   at java.sql.DriverManager.getConnection(Unknown Source)
                //   at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteConnection.Open(__SQLiteConnection.java:66)


                // https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/Vm5PTq4_0lg
                // Instance == Your Google API Project ID:InstanceName

                this.InternalConnection = DriverManager.getConnection(
                    OpenConnectionPrefix + x.Server,
                    x.UserID,
                    x.Password
                );
            }
            catch (Exception ex)
            {
                //        Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
                //at ScriptCoreLibJava.BCLImplementation.System.Data.SQLite.__SQLiteConnection.Open(__SQLiteConnection.java:39)
                //at ScriptCoreLib.Shared.Data.Diagnostics.WithConnectionLambda___c__DisplayClass2._WithConnection_b__1(WithConnectionLambda___c__DisplayClass2.java:36)

                if (ex.Message != null)
                    if (ex.Message.Contains("com.mysql.jdbc.Driver"))
                    {
                        // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAppEngineOrderByThenGroupBy\ApplicationWebService.cs

                        // "C:\util\appengine-java-sdk-1.9.2\lib\impl\mysql-connector-java-5.1.30-bin.jar"
                        // "C:\util\appengine-java-sdk-1.8.8\lib\impl\mysql-connector-java-5.1.22-bin.jar"
                        // "C:\util\appengine-java-sdk-1.9.9\lib\impl\mysql-connector-java-5.1.30-bin.jar"

                        // http://dev.mysql.com/downloads/connector/j/

                        Console.WriteLine(
                            @"!!! did you set up the mysql jar? check C:\util\appengine-java-sdk-1.9.9\lib\impl\mysql-connector-java-5.1.30-bin.jar"
                            );
                    }

                //                C:\Program Files (x86)\Java\jdk1.7.0_45\bin\javac.exe  -encoding UTF-8 -cp Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\release;C:\util\appengine-java-sdk-1.8.8\lib\impl\*;C:\util\appengine-java-sdk-1.8.8\lib\shared\* -d "Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\release" @"Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\files"

                //Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\java\ScriptCoreLibJava\BCLImplementation\System\Data\SQLite\__SQLiteConnection.java:47: error: unreported exception SQLException; must be caught or declared to be thrown
                //            throw exception1;
                //            ^
                //Note: Y:\AppEngineUserAgentLoggerWithXSLXAsset.ApplicationWebService\staging.java\web\java\ScriptCoreLibJava\BCLImplementation\System\Threading\__Thread.java uses or overrides a deprecated API.

                throw new InvalidOperationException("__SQLiteConnection " + new { ex.Message, ex.StackTrace });
            }

            // to be done by the user?
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAppEngineOrderByThenGroupBy\ApplicationWebService.cs


            //using (var cmd = new __SQLiteCommand(
            //    "CREATE DATABASE IF NOT EXISTS `" + this.InternalConnectionString.DataSource + "`",
            //    (__SQLiteConnection)(object)this))
            //{
            //    cmd.ExecuteNonQuery();
            //}


            //// http://stackoverflow.com/questions/1675333/php-mysql-joins-across-databases
            //using (var cmd = new __SQLiteCommand(
            //    "USE `" + this.InternalConnectionString.DataSource + "`",
            //    (__SQLiteConnection)(object)this))
            //{
            //    cmd.ExecuteNonQuery();
            //}

        }
        public override void Close()
        {
            //Console.WriteLine("__SQLiteConnection.Close");

            try
            {
                if (this.InternalConnection != null)
                {
                    this.InternalConnection.close();
                    this.InternalConnection = null;

                }

            }
            catch
            {
                throw;
            }
        }
Пример #6
0
		private void PrepareInternal()
		{
			if ((Connection == null) || (Connection.State != ConnectionState.Open)) {
				throw ExceptionHelper.ConnectionNotOpened("Prepare",(Connection != null) ? Connection.State.ToString() : "");
			}

			if (IsCommandPrepared) {
				// maybe we have to prepare the command again
				bool hasNullParameters = false;
				for(int i = 0; (i < Parameters.Count) && !hasNullParameters; i++) {
					AbstractDbParameter parameter = (AbstractDbParameter)Parameters[i];
					if (IsNullParameter(parameter)) {
						// if we still have null parameters - have to prepare agail
						IsCommandPrepared = false;
						hasNullParameters = true;
					}
				}

				if (!NullParametersInPrepare && hasNullParameters) {
					// if we prepeared using null parameters and now there is no null parameters - need to prepare again
					IsCommandPrepared = false;
				}
			}

			if (!IsCommandPrepared) {

				_javaCommandText = PrepareCommandTextAndParameters();

				java.sql.Connection jdbcCon = _connection.JdbcConnection;

				// For SchemaOnly we just prepare statement (for future use in GetSchemaTable)
				if (Behavior == CommandBehavior.SchemaOnly) {
					if (CommandType == CommandType.StoredProcedure)
						_statement = jdbcCon.prepareCall(_javaCommandText);
					else
						_statement = jdbcCon.prepareStatement(_javaCommandText);	
					return;
				}

				if (CommandType == CommandType.StoredProcedure)
					_statement = jdbcCon.prepareCall(_javaCommandText);
				else {
					int internalParametersCount = InternalParameters.Count;
					if ( internalParametersCount > 0) {
						bool hasOnlyInputParameters = true;
						for(int i=0; i < internalParametersCount; i++) {
							AbstractDbParameter internalParameter = (AbstractDbParameter)InternalParameters[i];
							if (IsNullParameter(internalParameter)) {
								NullParametersInPrepare = true;
							}

							if ((internalParameter.Direction & ParameterDirection.Output) != 0){
								hasOnlyInputParameters = false;
							}
						}

						if (hasOnlyInputParameters) {
							_statement = jdbcCon.prepareStatement(_javaCommandText);	
						}
						else {						
							_statement = jdbcCon.prepareCall(_javaCommandText);
						}
					}
					else {
						if (_explicitPrepare) {
							_statement = jdbcCon.prepareStatement(_javaCommandText);				
						}
						else {
							_statement = jdbcCon.createStatement();					
						}
					}
				}
				IsCommandPrepared = true;
			}
		}