public override void Close()
 {
     if (myThread != null)
     {
         myThread.Abort();
     }
     if (myDBConn != null)
     {
         myDBConn.Close();
     }
 }
Esempio n. 2
0
 public static bool check_func(FbConnectionStringBuilder fc)
 {
     bool res_ = false;
     using (FbConnection fb = new FbConnection(fc.ConnectionString))
     {
         try
         {
             fb.Open();
             using (FbTransaction ft = fb.BeginTransaction())
             {
                 using (FbCommand fcon = new FbCommand(sql_func,fb,ft))
                 {
                     using (FbDataReader fr = fcon.ExecuteReader())
                     {
                         while (fr.Read())
                         {
                             res_ = true;
                         }
                         fr.Dispose();
                     }
                     fcon.Dispose();
                 }
                 ft.Commit();
                 ft.Dispose();
             }
         }
         catch { }
         finally { fb.Close(); }
         fb.Dispose();
     }
     return res_;
 }
Esempio n. 3
0
        static int Main(string[] args)
        {
            int i = 0;
            int max = args.Length < 1 ? 1 : int.Parse(args[0]);
            while (i < max)
            {
                var connectionBuilder = new FbConnectionStringBuilder();
                connectionBuilder.DataSource = "localhost";
                connectionBuilder.Database = @"D:\db\Hoge2.FDB";
                connectionBuilder.Charset = FbCharset.Utf8.ToString();
                connectionBuilder.UserID = "SYSDBA";
                connectionBuilder.Password = "******";
                connectionBuilder.ServerType = FbServerType.Embedded;
                connectionBuilder.Pooling = false;

                using (var connection = new FbConnection(connectionBuilder.ConnectionString))
                {
                    connection.Open();
                    connection.Close();
                }
                i++;
            }
            UnloadDll(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"fbembed.dll"));
            return DateTime.Now.ToIntTime();
        }
Esempio n. 4
0
        public Conexao_Banco(/*string _codigo*/)
        {
            InitializeComponent();

            aux_codigo = tx_pesquisa.Text;
            //this.aux_codigo = _codigo;
            /*string caminho = @"C:\Sistema de Registro da Producao Ambulatorial\FBCADASTRO_AGENDA.FDB";
            string conexao = "User=SYSDBA;"
                + "PassWord=masterkey;"
                + "DataBase=" + caminho;*/
            //DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey; DBNAME=MyServer/3051:C:\database\myData.fdb;
            // @"DataSource=localhost; Database=C:\PastaFireBird\BANCOFIREBIRD.FDB;";
            //User=SYSDBA; Password=masterkey; Database=D:\Meus Documentos\Faculdade - Esucri\Programação avançada I\Delphi com Banco\Banco\BANCO.FDB; DataSource=192.168.0.100;Dialect=3;PacketSize = 4096;"
            string conexao = @"User=SYSDBA;Password=masterkey;Database=C:\Sistema de Registro da Producao Ambulatorial\FBCADASTRO_AGENDA.FDB;DataSource=RECEPCAO;Port=3050;Dialect=3;PacketSize=4096";

            _fbConexao = new FbConnection(conexao);

            try
            {
                _fbConexao.Open();

            }
            catch (Exception erro)
            {

                MessageBox.Show(erro.ToString());
            }
            dtgrd_view.DataSource = _dtTable;
            _fbConexao.Close();
        }
Esempio n. 5
0
        internal override void LoadAll()
        {
            try
            {
                var cn = new FbConnection(_dbRoot.ConnectionString);
                cn.Open();
                string dbName = cn.Database;
                cn.Close();

                int index = dbName.LastIndexOfAny(new[] {'\\'});

                if (index >= 0)
                {
                    dbName = dbName.Substring(index + 1);
                }

                // We add our one and only Database
                var database = (FirebirdDatabase) dbRoot.ClassFactory.CreateDatabase();
                database._name = dbName;
                database.dbRoot = dbRoot;
                database.Databases = this;
                _array.Add(database);
            }
            catch {}
        }
Esempio n. 6
0
        public List<belimpressao> BuscaDadosParaImpressao(List<belimpressao> objLista, FbConnection Conn)
        {
            try
            {
                for (int i = 0; i < objLista.Count; i++)
                {
                    StringBuilder sQuery = new StringBuilder();
                    sQuery.Append("select nf.cd_verificacao_nfse, nf.cd_numero_nfse from nf ");
                    sQuery.Append("where nf.cd_nfseq = '" + objLista[i].sNfSeq + "' and ");
                    sQuery.Append("nf.cd_empresa = '" + belStatic.codEmpresaNFe + "'");

                    FbCommand Command = new FbCommand(sQuery.ToString(), Conn);
                    if (Conn.State == System.Data.ConnectionState.Closed)
                    {
                        Conn.Open();
                    }
                    FbDataReader dr = Command.ExecuteReader();
                    dr.Read();
                    objLista[i].sNota = dr["cd_numero_nfse"].ToString();
                    objLista[i].sVerificacao = dr["cd_verificacao_nfse"].ToString();
                }
                if (Conn.State == System.Data.ConnectionState.Open)
                {
                    Conn.Close();
                }
                return objLista;
            }
            catch (Exception)
            {

                throw;
            }
        }
Esempio n. 7
0
        public DataTable RetornaNomeUsuarioCadastrado(string prontuario)
        {
            FbConnection conex = new FbConnection(conexao);

            string query = "SELECT * FROM TBUSUARIO WHERE CDUSUARIO = '"+prontuario+"'";
            FbCommand comando = new FbCommand(query, conex);
            try
            {

                conex.Open();

                FbDataAdapter datareader = new FbDataAdapter(comando);
                DataTable usuarios = new DataTable();
                datareader.Fill(usuarios);
                return usuarios;
            }
            catch (Exception err)
            {

                throw err;
            }
            finally
            {
                conex.Close();
            }
        }
Esempio n. 8
0
        override internal void LoadAll()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                string dbName = cn.Database;
                cn.Close();

                int index = dbName.LastIndexOfAny(new char[] { '\\' });

                if (index >= 0)
                {
                    dbName = dbName.Substring(index + 1);
                }

                // We add our one and only Database
                FirebirdDatabase database = (FirebirdDatabase)this.dbRoot.ClassFactory.CreateDatabase();
                database._name     = dbName;
                database.dbRoot    = this.dbRoot;
                database.Databases = this;
                this._array.Add(database);
            }
            catch {}
        }
Esempio n. 9
0
        public static bool ContratoTemItens(string contrato)
        {
            bool retorno = false;

            conn = AcessoDados.AcessoDados.getConn();

            FbCommand comando = new FbCommand("select COUNT(*) as contador from sci_licitacao_contrato_itens lci where lci.ctrcod = @CONTRATO",conn);

            FbParameter IDCONTRATO = new FbParameter("@CONTRATO", FbDbType.Integer);
            IDCONTRATO.Value = contrato;
            comando.Parameters.Add(IDCONTRATO);

            conn.Open();
            FbDataReader dr = comando.ExecuteReader();
            while (dr.Read()) {
                if (Convert.ToInt16(dr["contador"]) > 0)
                {
                    retorno = true;
                }
                else {
                    retorno = false;
                }
            }
            conn.Close();
            comando.Dispose();
            return retorno;
        }
Esempio n. 10
0
        override internal void LoadForTable()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Columns", new string[] { null, null, this.Table.Name });

                DataColumn c;
                if (!metaData.Columns.Contains("IS_AUTO_KEY"))
                {
                    c = metaData.Columns.Add("IS_AUTO_KEY", typeof(Boolean)); c.DefaultValue = false;
                }
                if (!metaData.Columns.Contains("AUTO_KEY_SEED"))
                {
                    c = metaData.Columns.Add("AUTO_KEY_SEED"); c.DefaultValue = 0;
                }
                if (!metaData.Columns.Contains("AUTO_KEY_INCREMENT"))
                {
                    c = metaData.Columns.Add("AUTO_KEY_INCREMENT"); c.DefaultValue = 0;
                }
                if (!metaData.Columns.Contains("AUTO_KEY_SEQUENCE"))
                {
                    c = metaData.Columns.Add("AUTO_KEY_SEQUENCE"); c.DefaultValue = string.Empty;
                }

                PopulateArray(metaData);
                LoadExtraData(cn, this.Table.Name, "T");
                cn.Close();
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 11
0
        private FbOptions GetSettings(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                connectionString = Settings.Connection.ConnectionString;
            }
            if (ServerVersion != null)
            {
                return(this);
            }

            try
            {
                using (var connection = new Firebird.FbConnection(connectionString))
                {
                    connection.Open();
                    ServerVersion = Data.FbServerProperties.ParseServerVersion(connection.ServerVersion);
                    using (var cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = "SELECT MON$SQL_DIALECT FROM MON$DATABASE";
                        IsLegacyDialect = Convert.ToInt32(cmd.ExecuteScalar()) == 1;
                    }
                    connection.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(this);
        }
Esempio n. 12
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;
        }
		public void BeginTrasactionTest()
		{
			string connectionString = this.BuildConnectionString();

			FbConnection conn01 = new FbConnection(connectionString);
			conn01.Open();
			FbTransaction txn01 = conn01.BeginTransaction(IsolationLevel.Unspecified);
			txn01.Rollback();
			conn01.Close();

			FbConnection conn02 = new FbConnection(connectionString);
			conn02.Open();
			FbTransaction txn02 = conn02.BeginTransaction(IsolationLevel.ReadCommitted);
			txn02.Rollback();
			conn02.Close();

			FbConnection conn03 = new FbConnection(connectionString);
			conn03.Open();
			FbTransaction txn03 = conn03.BeginTransaction(IsolationLevel.ReadUncommitted);
			txn03.Rollback();
			conn03.Close();

			FbConnection conn04 = new FbConnection(connectionString);
			conn04.Open();
			FbTransaction txn04 = conn04.BeginTransaction(IsolationLevel.RepeatableRead);
			txn04.Rollback();
			conn04.Close();

			FbConnection conn05 = new FbConnection(connectionString);
			conn05.Open();
			FbTransaction txn05 = conn05.BeginTransaction(IsolationLevel.Serializable);
			txn05.Rollback();
			conn05.Close();
		}
Esempio n. 14
0
        private string NomeArqCte()
        {
            FbConnection con = null;
            try
            {
                string sNomeArq = "";
                FbCommand cmd = new FbCommand();
                con = new FbConnection(HlpDbFuncoesGeral.MontaStringConexao());
                cmd.Connection = con;
                con.Open();
                cmd.CommandText = "SP_CHAVEPRI";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Clear();

                cmd.Parameters.Add("@SNOMEGENERATOR", FbDbType.VarChar, 31).Value = "GEN_NOMEARQXML";

                sNomeArq = cmd.ExecuteScalar().ToString();

                return "Cte_" + sEmp + sNomeArq.PadLeft(15, '0') + ".xml";
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

        }
Esempio n. 15
0
		override internal void LoadAll()
		{
			try
			{
				FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
				cn.Open();
				string dbName = cn.Database;
				cn.Close();

				int index = dbName.LastIndexOfAny(new char[]{'\\'});

				if (index >= 0)
				{
					dbName = dbName.Substring(index + 1);
				}

				// We add our one and only Database
				FirebirdDatabase database = (FirebirdDatabase)this.dbRoot.ClassFactory.CreateDatabase();
				database._name = dbName;
				database.dbRoot = this.dbRoot;
				database.Databases = this;
				this._array.Add(database);
			}
			catch {}
		}
Esempio n. 16
0
        public tcDadosConstrucaoCivil RettcDadosConstrucaoCivil(FbConnection Conn, string sNota)
        {

            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("select coalesce(clifor.cd_art,'') Art, coalesce(clifor.cd_obra,'')CodigoObra {0}");
                sQuery.Append("from nf inner join clifor on nf.cd_clifor = clifor.cd_clifor {0}");
                sQuery.Append("where nf.cd_nfseq = '{1}' and nf.cd_empresa = '{2}' {0}");

                string sQueryEnd = string.Format(sQuery.ToString(), Environment.NewLine, sNota, belStatic.codEmpresaNFe);

                FbCommand cmd = new FbCommand(sQueryEnd, Conn);
                Conn.Open();
                FbDataReader dr = cmd.ExecuteReader();
                objtcDadosConstrucaoCivil = new tcDadosConstrucaoCivil();
                while (dr.Read())
                {
                    objtcDadosConstrucaoCivil.Art = dr["Art"].ToString();
                    objtcDadosConstrucaoCivil.CodigoObra = dr["CodigoObra"].ToString();
                }

            }
            catch (Exception)
            {
                throw;
            }
            finally { Conn.Close(); }


            return objtcDadosConstrucaoCivil;
        }
Esempio n. 17
0
        public bool OpenConnection()
        {
            //// Set the ServerType to 1 for connect to the embedded server
            //string connectionString =
            //"User=SYSDBA;" +
            //"Password=masterkey;" +
            //"Database=C:/Users/ikhromov/Desktop/Domovoy_prj/4rmd.gdb;" +
            //"DataSource=localhost;" +
            //"Port=3050;" +
            //"Dialect=3;" +
            //"Charset=NONE;" +
            //"Role=;" +
            //"Connection lifetime=15;" +
            //"Pooling=true;" +
            //"MinPoolSize=0;" +
            //"MaxPoolSize=50;" +
            //"Packet Size=8192;" +
            //"ServerType=0";

            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["domovoyDBConnection"].ConnectionString;
                fbConnection = new FbConnection(connectionString);
                // Open connection.
                fbConnection.Open();
                fbConnection.Close();
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
Esempio n. 18
0
        public override void execute(Options options, INIManager iniManager)
        {
            string AppKey = iniManager.IniReadValue("APP", "AppKey");
            string AppSecret = iniManager.IniReadValue("APP", "AppSecret");
            string TaobaoAsistantPath = iniManager.IniReadValue("淘宝助理", "安装目录");

            string nick = options.Nick;
            string SessionKey = iniManager.IniReadValue(nick, "SessionKey");

            string userId = iniManager.IniReadValue(nick, "UserId");
            if (userId == null || userId.Trim().Equals(""))
            {
                userId = "1696293148";
            }

            StreamWriter MovePicLogWriter;

            FileStream MovePicLog = new FileStream(Environment.CurrentDirectory + "\\" + "MovePic.log", FileMode.Append);
            MovePicLogWriter = new StreamWriter(MovePicLog, Encoding.Default);
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
            cs.Database = Path.Combine(TaobaoAsistantPath, "users\\" + nick + "\\APPITEM.DAT");
            cs.Charset = "UTF8";
            cs.UserID = "SYSDBA";
            cs.Password = "******";
            cs.ServerType = FbServerType.Embedded;
            FbConnection fbCon = new FbConnection(cs.ToString());
            fbCon.Open();

            FbCommand ItemsCommand = null;
            ItemsCommand = new FbCommand("SELECT * FROM ITEM WHERE OUTER_ID = @SearchString OR TITLE = @SearchString", fbCon);
            FbParameter SearchString = new FbParameter("@SearchString", FbDbType.VarChar);
            SearchString.Value = options.Item;
            ItemsCommand.Parameters.Add(SearchString);

            FbDataReader ItemsReader = ItemsCommand.ExecuteReader();
            while (ItemsReader.Read())
            {
                MovePicLogWriter.WriteLine("--------------------------------------------------------------------------------");
                Console.WriteLine("--------------------------------------------------------------------------------");
                string ClientID = ItemsReader["CLIENT_ID"].ToString();
                string Title = ItemsReader["TITLE"].ToString();
                Console.WriteLine("ClientID=" + ClientID);
                MovePicLogWriter.WriteLine("ClientID=" + ClientID);
                Console.WriteLine("TITLE=" + Title);

                MovePicLogWriter.WriteLine("TITLE=" + Title);
                FbTransaction myTransaction = fbCon.BeginTransaction();
                FbCommand DeleteCommand = new FbCommand("UPDATE ITEM SET CLIENT_IS_DELETE = 1 WHERE CLIENT_ID = @ClientID", fbCon);
                FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                ParamID.Value = ClientID;
                DeleteCommand.Parameters.Add(ParamID);
                DeleteCommand.Transaction = myTransaction;
                DeleteCommand.ExecuteNonQuery();
                myTransaction.Commit();
            }
            fbCon.Close();
            MovePicLogWriter.Close();
            MovePicLog.Close();
        }
Esempio n. 19
0
 public static DataTable EleentsToDataTable(string command)
 {
     var dt = new DataTable();
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbDataAdapter da = new FbDataAdapter(command, con);
     da.Fill(dt);
     con.Close();
     return dt;
 }
Esempio n. 20
0
 public static void DatabaseCommand(string command)
 {
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     transaction.Commit();
     con.Close();
 }
Esempio n. 21
0
		override internal void LoadAll()
		{
			try
			{
				FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
				cn.Open();
				DataTable metaData = cn.GetSchema("Procedures", new string[] {this.Database.Name});
				cn.Close();

				PopulateArray(metaData);
			}
			catch(Exception ex)
			{
				string m = ex.Message;
			}
		}
Esempio n. 22
0
        internal override void LoadAll()
        {
            try
            {
                var cn = new FbConnection(_dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Procedures", new[] {Database.Name});
                cn.Close();

                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 23
0
        override internal void LoadAll()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Procedures", new string[] { this.Database.Name });
                cn.Close();

                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 24
0
        public PacienteFirebird()
        {
            FbConnection connex = new FbConnection(conexao);
            try
            {
                conexao = Datasource + DataBase + user + password;
                connex = new FbConnection(conexao);
                connex.Open();
            }
            catch (Exception err)
            {
                connex.Close();
                System.Windows.Forms.MessageBox.Show(err.Message);

            }
        }
Esempio n. 25
0
        public ConexaoFirebird()
        {
            FbConnection connex = new FbConnection(conexao);
            try
            {
                conexao = Datasource + DataBase + user + password;
                connex = new FbConnection(conexao);
                connex.Open();
            }
            catch (Exception)
            {
                connex.Close();
                throw;

            }
        }
Esempio n. 26
0
        override internal void LoadAll()
        {
            try
            {
                using (FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString))
                {
                    cn.Open();

                    DataTable idxMetaData = cn.GetSchema("Indexes", new string[] { null, null, this.Table.Name });

                    if (!idxMetaData.Columns.Contains("CARDINALITY"))
                    {
                        idxMetaData.Columns.Add("CARDINALITY");
                    }
                    if (!idxMetaData.Columns.Contains("COLUMN_NAME"))
                    {
                        idxMetaData.Columns.Add("COLUMN_NAME");
                    }

                    idxMetaData.Columns["IS_UNIQUE"].ColumnName  = "UNIQUE";
                    idxMetaData.Columns["INDEX_TYPE"].ColumnName = "TYPE";

                    DataTable metaData = idxMetaData.Clone();
                    metaData.Clear();
                    foreach (DataRow row in idxMetaData.Rows)
                    {
                        string    indexName       = (string)row["INDEX_NAME"];
                        DataTable metaDataColumns = cn.GetSchema("IndexColumns", new string[] { null, null, null, indexName });
                        metaDataColumns.DefaultView.Sort = "ORDINAL_POSITION ASC";
                        foreach (DataRowView vrow in metaDataColumns.DefaultView)
                        {
                            DataRow newrow = metaData.Rows.Add(row.ItemArray);
                            newrow["CARDINALITY"] = vrow["ORDINAL_POSITION"];
                            newrow["COLUMN_NAME"] = vrow["COLUMN_NAME"];
                        }
                    }
                    cn.Close();

                    PopulateArray(metaData);
                }
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 27
0
 public static string GetOneElement(string command)
 {
     string element = "";
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     FbDataReader datareader;
     datareader = com.ExecuteReader();
     while (datareader.Read())
     {
         element = datareader[0].ToString();
     }
     con.Close();
     return element;
 }
Esempio n. 28
0
        internal override void LoadForTable()
        {
            try
            {
                var cn = new FbConnection(_dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Columns", new[] {null, null, Table.Name});

                PopulateArray(metaData);
                LoadExtraData(cn, Table.Name, "T");
                cn.Close();
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 29
0
File: Tables.cs Progetto: zxbe/OMeta
        override internal void LoadAll()
        {
            try
            {
                string type = this.dbRoot.ShowSystemData ? "SYSTEM TABLE" : "TABLE";

                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Tables", new string[] { null, null, null, type });
                cn.Close();

                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 30
0
		override internal void LoadAll()
		{
			try
			{
				FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
				cn.Open();
				DataTable metaData = cn.GetSchema("Views", new string[] {null, null, null});
				cn.Close();

				metaData.Columns["VIEW_NAME"].ColumnName = "TABLE_NAME";

				PopulateArray(metaData);
			}
			catch(Exception ex)
			{
				string m = ex.Message;
			}
		}
Esempio n. 31
0
		override internal void LoadAll()
		{
			try
			{
				string type = this.dbRoot.ShowSystemData ? "SYSTEM TABLE" : "TABLE";

				FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
				cn.Open();
				DataTable metaData = cn.GetSchema("Tables", new string[] {null, null, null, type});
				cn.Close();

				PopulateArray(metaData);
			}
			catch(Exception ex)
			{
				string m = ex.Message;
			}
		}
Esempio n. 32
0
        internal override void LoadAll()
        {
            try
            {
                string type = dbRoot.ShowSystemData ? "SYSTEM TABLE" : "TABLE";

                var cn = new FbConnection(_dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Tables", new[] {null, null, null, type});
                cn.Close();

                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 33
0
        override internal void LoadForView()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();

                DataTable metaData = cn.GetSchema("Columns", new string[] { null, null, this.View.Name });

                PopulateArray(metaData);
                LoadExtraData(cn, this.View.Name, "V");
                cn.Close();
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 34
0
		override internal void LoadForView()
		{
			try
			{
				FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
				cn.Open();

				DataTable metaData = cn.GetSchema("Columns", new string[] {null, null, this.View.Name});

                PopulateArray(metaData);
				LoadExtraData(cn, this.View.Name, "V");
				cn.Close();				
			}
			catch(Exception ex)
			{
				string m = ex.Message;
			}
		}
Esempio n. 35
0
        override internal void LoadAll()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Views", new string[] { null, null, null });
                cn.Close();

                metaData.Columns["VIEW_NAME"].ColumnName = "TABLE_NAME";

                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 36
0
 public static bool ExistsElement(string command)
 {
     string element = "";
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     FbDataReader datareader;
     datareader = com.ExecuteReader();
     while (datareader.Read())
     {
         element = datareader[0].ToString();
     }
     con.Close();
     if (element != null && element != "")
         return true;
     return false;
 }
Esempio n. 37
0
        internal override void LoadAll()
        {
            try
            {
                var cn = new FbConnection(_dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Indexes", new[] {null, null, Table.Name});
                cn.Close();

                metaData.Columns["IS_UNIQUE"].ColumnName = "UNIQUE";
                metaData.Columns["INDEX_TYPE"].ColumnName = "TYPE";
                metaData.Columns["ORDINAL_POSITION"].ColumnName = "CARDINALITY";
                PopulateArray(metaData);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
        public FbConnection MontaConexaoEscritor()
        {
            FbConnection Conn = new FbConnection();
            try
            {

                Globais MontaStringConexao = new Globais();
                StringBuilder sbConexao = new StringBuilder();

                sbConexao.Append("User ="******"Usuario"));
                sbConexao.Append(";");
                sbConexao.Append("Password="******"Senha"));
                sbConexao.Append(";");
                sbConexao.Append("Database=");
                string sdatabase = MontaStringConexao.LeRegConfig("BancoEscritor");
                sbConexao.Append(sdatabase);
                sbConexao.Append(";");
                sbConexao.Append("DataSource=");
                sbConexao.Append(MontaStringConexao.LeRegConfig("ServidorEscritor"));
                sbConexao.Append(";");
                sbConexao.Append("Port=3050;Dialect=1; Charset=NONE;Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;");


                Conn = new FbConnection(sbConexao.ToString());
                Conn.Open();
                return Conn;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Não foi possivel se conectar ao banco de dados do Escritor, Verifique as Configurações do Sistema, Erro.: {0}",
                                                  ex.Message));
            }
            finally
            {
                Conn.Close();
            }

            return Conn;
        }
Esempio n. 39
0
		override internal void LoadAll()
		{
			try
			{
                using (FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString))
                {
                    cn.Open();
                    
                    DataTable idxMetaData = cn.GetSchema("Indexes", new string[] { null, null, this.Table.Name });

                    if (!idxMetaData.Columns.Contains("CARDINALITY")) idxMetaData.Columns.Add("CARDINALITY");
                    if (!idxMetaData.Columns.Contains("COLUMN_NAME")) idxMetaData.Columns.Add("COLUMN_NAME");

                    idxMetaData.Columns["IS_UNIQUE"].ColumnName = "UNIQUE";
                    idxMetaData.Columns["INDEX_TYPE"].ColumnName = "TYPE";

                    DataTable metaData = idxMetaData.Clone();
                    metaData.Clear();
                    foreach (DataRow row in idxMetaData.Rows)
                    {
                        string indexName = (string)row["INDEX_NAME"];
                        DataTable metaDataColumns = cn.GetSchema("IndexColumns", new string[] { null, null, null, indexName });
                        metaDataColumns.DefaultView.Sort = "ORDINAL_POSITION ASC";
                        foreach (DataRowView vrow in metaDataColumns.DefaultView)
                        {
                            DataRow newrow = metaData.Rows.Add(row.ItemArray);
                            newrow["CARDINALITY"] = vrow["ORDINAL_POSITION"];
                            newrow["COLUMN_NAME"] = vrow["COLUMN_NAME"];
                        }
                    }
                    cn.Close();
                 
                    PopulateArray(metaData);
                }
			}
			catch(Exception ex)
			{
				string m = ex.Message;
			}
		}
Esempio n. 40
0
        override internal void LoadAll()
        {
            try
            {
                FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();
                DataTable metaData = cn.GetSchema("Domains", null);
                cn.Close();

                if (metaData.Columns.Contains("DOMAIN_DATA_TYPE"))
                {
                    metaData.Columns["DOMAIN_DATA_TYPE"].ColumnName = "DATA_TYPE";
                }

                PopulateArray(metaData);

                LoadExtraData(cn);
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }
Esempio n. 41
0
        private void FixupDataTypes(DataTable metaData)
        {
            FbConnection cn = null;

            try
            {
                int dialect = 1;

                cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString);
                cn.Open();

                try
                {
                    FbConnectionStringBuilder cnString = new FbConnectionStringBuilder(cn.ConnectionString);
                    dialect = cnString.Dialect;
                }
                catch {}

                int       count = this._array.Count;
                Parameter p     = null;

                if (count > 0)
                {
                    // Dimension Data
                    string dimSelect = "select r.rdb$field_name AS Name , d.rdb$dimension as DIM, d.rdb$lower_bound as L, d.rdb$upper_bound as U from rdb$fields f, rdb$field_dimensions d, rdb$relation_fields r where r.rdb$relation_name='" + this.Procedure.Name + "' and f.rdb$field_name = d.rdb$field_name and f.rdb$field_name=r.rdb$field_source order by d.rdb$dimension;";

                    FbDataAdapter dimAdapter = new FbDataAdapter(dimSelect, cn);
                    DataTable     dimTable   = new DataTable();
                    dimAdapter.Fill(dimTable);

                    p = this._array[0] as Parameter;

                    f_TypeName = new DataColumn("TYPE_NAME", typeof(string));
                    p._row.Table.Columns.Add(f_TypeName);

                    f_TypeNameComplete = new DataColumn("TYPE_NAME_COMPLETE", typeof(string));
                    p._row.Table.Columns.Add(f_TypeNameComplete);

                    short             ftype = 0;
                    short             dim   = 0;
                    DataRowCollection rows  = metaData.Rows;

                    for (int index = 0; index < count; index++)
                    {
                        p = (Parameter)this[index];

                        if (p._row["NUMERIC_PRECISION"] == System.DBNull.Value)
                        {
                            p._row["NUMERIC_PRECISION"] = p._row["PARAMETER_SIZE"];
                        }

                        p._row["PARAMETER_NAME"] = (p._row["PARAMETER_NAME"] as String).Trim();

                        int dir = (int)p._row["PARAMETER_TYPE"];


                        p._row["PARAMETER_TYPE"] = dir == 0 ? 1 : 3;


                        // Step 1: DataTypeName
                        ftype = (short)rows[index]["FIELD_TYPE"];

                        switch (ftype)
                        {
                        case 7:
                            p._row["TYPE_NAME"] = "SMALLINT";
                            break;

                        case 8:
                            p._row["TYPE_NAME"] = "INTEGER";
                            break;

                        case 9:
                            p._row["TYPE_NAME"] = "QUAD";
                            break;

                        case 10:
                            p._row["TYPE_NAME"] = "FLOAT";
                            break;

                        case 11:
                            p._row["TYPE_NAME"] = "DOUBLE PRECISION";
                            break;

                        case 12:
                            p._row["TYPE_NAME"] = "DATE";
                            break;

                        case 13:
                            p._row["TYPE_NAME"] = "TIME";
                            break;

                        case 14:
                            p._row["TYPE_NAME"] = "CHAR";
                            break;

                        case 16:
                            if (p.NumericScale < 0)
                            {
                                p._row["TYPE_NAME"] = "NUMERIC";
                            }
                            else
                            {
                                p._row["TYPE_NAME"] = "BIGINT";
                            }
                            break;

                        case 27:
                            p._row["TYPE_NAME"] = "DOUBLE PRECISION";
                            break;

                        case 35:

                            if (dialect > 2)
                            {
                                p._row["TYPE_NAME"] = "TIMESTAMP";
                            }
                            else
                            {
                                p._row["TYPE_NAME"] = "DATE";
                            }
                            break;

                        case 37:
                            p._row["TYPE_NAME"] = "VARCHAR";
                            break;

                        case 40:
                            p._row["TYPE_NAME"] = "CSTRING";
                            break;

                        case 261:
                            short subtype = (short)rows[index]["PARAMETER_SUB_TYPE"];

                            switch (subtype)
                            {
                            case 0:
                                p._row["TYPE_NAME"] = "BLOB(BINARY)";
                                break;

                            case 1:
                                p._row["TYPE_NAME"] = "BLOB(TEXT)";
                                break;

                            default:
                                p._row["TYPE_NAME"] = "BLOB(UNKNOWN)";
                                break;
                            }
                            break;
                        }

                        int scale = p.NumericScale;
                        if (scale < 0)
                        {
                            p._row["TYPE_NAME"]     = "NUMERIC";
                            p._row["NUMERIC_SCALE"] = Math.Abs(scale);
                        }


                        // Step 2: DataTypeNameComplete
                        string s = p._row["TYPE_NAME"] as string;
                        switch (s)
                        {
                        case "VARCHAR":
                        case "CHAR":
                            p._row["TYPE_NAME_COMPLETE"] = s + "(" + p.CharacterMaxLength + ")";
                            break;

                        case "NUMERIC":

                            switch ((int)p._row["PARAMETER_SIZE"])
                            {
                            case 2:
                                p._row["TYPE_NAME_COMPLETE"] = s + "(4, " + p.NumericScale.ToString() + ")";
                                break;

                            case 4:
                                p._row["TYPE_NAME_COMPLETE"] = s + "(9, " + p.NumericScale.ToString() + ")";
                                break;

                            case 8:
                                p._row["TYPE_NAME_COMPLETE"] = s + "(15, " + p.NumericScale.ToString() + ")";
                                break;

                            default:
                                p._row["TYPE_NAME_COMPLETE"] = "NUMERIC(18,0)";
                                break;
                            }
                            break;

                        case "BLOB(TEXT)":
                        case "BLOB(BINARY)":
                            p._row["TYPE_NAME_COMPLETE"] = "BLOB";
                            break;

                        default:
                            p._row["TYPE_NAME_COMPLETE"] = s;
                            break;
                        }

                        s = p._row["TYPE_NAME_COMPLETE"] as string;

                        dim = 0;
                        object o = rows[index]["DIM"];
                        if (o != DBNull.Value)
                        {
                            dim = (short)o;
                        }

                        if (dim > 0)
                        {
                            dimTable.DefaultView.RowFilter = "Name = '" + p.Name + "'";
                            dimTable.DefaultView.Sort      = "DIM";

                            string a      = "[";
                            bool   bFirst = true;

                            foreach (DataRowView vrow in dimTable.DefaultView)
                            {
                                DataRow row = vrow.Row;

                                if (!bFirst)
                                {
                                    a += ",";
                                }

                                a += row["L"].ToString() + ":" + row["U"].ToString();

                                bFirst = false;
                            }

                            a += "]";

                            p._row["TYPE_NAME_COMPLETE"] = s + a;

                            p._row["TYPE_NAME"] = p._row["TYPE_NAME"] + ":A";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string e = ex.Message;
            }

            if (cn != null)
            {
                cn.Close();
            }
        }
Esempio n. 42
0
        override internal void LoadAll()
        {
            try
            {
                using (FbConnection cn = new FirebirdSql.Data.FirebirdClient.FbConnection(this._dbRoot.ConnectionString))
                {
                    cn.Open();
                    if (allFkData == null)
                    {
                        allFkData = cn.GetSchema("ForeignKeys");
                        allFkData.Columns.Add("COLUMN_NAME");
                        allFkData.Columns.Add("REFERENCED_COLUMN_NAME");
                        allFkData.Columns.Add("ORDINAL_POSITION");
                        allFkData.Columns.Add("DEFERRABILITY");

                        mappingHash = new NameValueCollection();
                        mappingHash["FK_TABLE_CATALOG"] = "TABLE_CATALOG";
                        mappingHash["FK_TABLE_SCHEMA"]  = "TABLE_SCHEMA";
                        mappingHash["FK_TABLE_NAME"]    = "TABLE_NAME";
                        mappingHash["PK_TABLE_CATALOG"] = "REFERENCED_TABLE_CATALOG";
                        mappingHash["PK_TABLE_SCHEMA"]  = "REFERENCED_TABLE_SCHEMA";
                        mappingHash["PK_TABLE_NAME"]    = "REFERENCED_TABLE_NAME";
                        mappingHash["ORDINAL"]          = "ORDINAL_POSITION";
                        mappingHash["UPDATE_RULE"]      = "UPDATE_RULE";
                        mappingHash["DELETE_RULE"]      = "DELETE_RULE";
                        mappingHash["PK_NAME"]          = "INDEX_NAME";
                        mappingHash["FK_NAME"]          = "CONSTRAINT_NAME";
                        mappingHash["DEFERRABILITY"]    = "DEFERRABILITY";
                    }

                    DataTable metaData = allFkData.Clone();
                    metaData.Clear();
                    foreach (DataRow row in allFkData.Rows)
                    {
                        if ((this.Table.Name == (string)row["TABLE_NAME"]) ||
                            (this.Table.Name == (string)row["REFERENCED_TABLE_NAME"]))
                        {
                            string indexName    = (string)row["INDEX_NAME"];
                            string refTableName = (string)row["REFERENCED_TABLE_NAME"];
                            string isDef        = (string)row["IS_DEFERRABLE"];
                            string initDef      = (string)row["INITIALLY_DEFERRED"];


                            row["DEFERRABILITY"] = (isDef == "NO" ? 3 : (initDef == "YES" ? 2 : 1));
                            DataTable metaDataColumns = cn.GetSchema("IndexColumns", new string[] { null, null, null, indexName });
                            metaDataColumns.DefaultView.Sort = "ORDINAL_POSITION ASC";

                            DataTable metaDataPKIndex = cn.GetSchema("Indexes", new string[] { null, null, refTableName });
                            metaDataPKIndex.DefaultView.RowFilter = "IS_PRIMARY = True";

                            string refPkIndexName = (string)metaDataPKIndex.DefaultView[0]["INDEX_NAME"];

                            DataTable metaDataColumnsRefPk = cn.GetSchema("IndexColumns", new string[] { null, null, null, refPkIndexName });
                            metaDataColumnsRefPk.DefaultView.Sort = "ORDINAL_POSITION ASC";

                            if (metaDataColumnsRefPk.Rows.Count == metaDataColumns.Rows.Count)
                            {
                                for (int i = 0; i < metaDataColumnsRefPk.Rows.Count; i++)
                                {
                                    DataRow newrow = metaData.Rows.Add(row.ItemArray);
                                    newrow["ORDINAL_POSITION"]       = metaDataColumnsRefPk.DefaultView[i]["ORDINAL_POSITION"];
                                    newrow["COLUMN_NAME"]            = metaDataColumns.DefaultView[i]["COLUMN_NAME"];
                                    newrow["REFERENCED_COLUMN_NAME"] = metaDataColumnsRefPk.DefaultView[i]["COLUMN_NAME"];
                                }
                            }
                        }
                    }
                    cn.Close();

                    PopulateArrayNoHookup(metaData, mappingHash);

                    ForeignKey key     = null;
                    string     keyName = "";

                    foreach (DataRow row in metaData.Rows)
                    {
                        keyName = row["CONSTRAINT_NAME"] as string;

                        key = this.GetByName(keyName);

                        key.AddForeignColumn(null, null, (string)row["TABLE_NAME"], (string)row["COLUMN_NAME"], false);
                        key.AddForeignColumn(null, null, (string)row["REFERENCED_TABLE_NAME"], (string)row["REFERENCED_COLUMN_NAME"], true);
                    }
                }
            }
            catch (Exception ex)
            {
                string m = ex.Message;
            }
        }