Ejemplo n.º 1
0
        public static bool UpgradeThis(string sqlfilename)
        {
            Assembly     _assembly;
            StreamReader _textStreamReader;

            string resname = "KlonsF.SQL." + sqlfilename + ".txt";

            _assembly         = Assembly.GetExecutingAssembly();
            _textStreamReader = new StreamReader(
                _assembly.GetManifestResourceStream(resname));

            string sql = _textStreamReader.ReadToEnd();

            FbConnection conn = DataSetHelper.GetFbConnection(KlonsData.St.KlonsTableAdapterManager.ParamsTableAdapter);

            if (conn == null)
            {
                return(false);
            }

            FbScript script = new FbScript(sql);

            script.Parse();

            FbBatchExecution fbe = new FbBatchExecution(conn);

            foreach (var cmd in script.Results)
            {
                fbe.Statements.Add(cmd);
            }

            fbe.Execute();

            return(true);
        }
Ejemplo n.º 2
0
        public static bool ExecuteBatchScript(
            string connectionString,
            string pathToScriptFile)
        {
            FbScript script = new FbScript(pathToScriptFile);

            if (script.Parse() > 0)
            {
                using (FbConnection connection = new FbConnection(connectionString))
                {
                    connection.Open();
                    try
                    {
                        FbBatchExecution batch = new FbBatchExecution(connection, script);
                        batch.Execute(true);
                    }
                    catch (FbException ex)
                    {
                        log.Error(ex);
                        throw new Exception(pathToScriptFile, ex);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

            return(true);
        }
 private static void ExecuteDbCreationScript()
 {
     using (var connection = new FbConnection(GetConnectionString()))
     {
         var batchExecution = new FbBatchExecution(connection);
         var script         = new FbScript(DbCreationScript ?? Resources.create_db);
         script.Parse();
         batchExecution.AppendSqlStatements(script);
         batchExecution.Execute();
     }
 }
Ejemplo n.º 4
0
 //teste para bloco de codigo
 public static void ExecuteCommandBloco(string ibge, string scripttext)
 {
     using (var conn = new FbConnection(ibge))
     {
         conn.Open();
         FbScript script = new FbScript(scripttext);
         script.Parse();
         FbBatchExecution fbe = new FbBatchExecution(conn);
         fbe.AppendSqlStatements(script);
         fbe.Execute();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses the script.
        /// </summary>
        /// <param name="scriptText">The script text.</param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public static FbStatementCollection ParseScript(string scriptText, EventHandler <UnknownStatementEventArgs> handler)
        {
            FbScript script = new FbScript(scriptText);

            //Set unkown statement handler
            script.UnknownStatement += handler;

            //Parse the script
            script.Parse();

            //Return the results back to the caller
            return(script.Results);
        }
Ejemplo n.º 6
0
        private void CreateDatabase()
        {
            // create db folder
            var dbFolderPath = Path.GetDirectoryName(this.dbPath);

            if (!Directory.Exists(dbFolderPath))
            {
                Directory.CreateDirectory(dbFolderPath);
            }

            if (!File.Exists(this.dbPath))
            {
                try
                {
                    var connString = @"ServerType=1; DataSource=localhost; Database={0}; Pooling=false; User=SYSDBA; Password=NA;".Format2(this.dbPath);

                    FbConnection.CreateDatabase(connString);

                    var assembly = Assembly.GetExecutingAssembly();
                    using (var conn = new FbConnection(connString))
                        using (var stream = assembly.GetManifestResourceStream("BitSharp.Storage.Firebird.Sql.CreateDatabase.sql"))
                            using (var reader = new StreamReader(stream))
                            {
                                conn.Open();

                                var script = new FbScript(reader.ReadToEnd());
                                script.Parse();

                                new FbBatchExecution(conn, script).Execute();
                            }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Database create failed: {0}".Format2(e.Message));
                    Debugger.Break();

                    if (File.Exists(this.dbPath))
                    {
                        File.Delete(this.dbPath);
                    }

                    throw;
                }
            }
        }