protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     Xdr.Write(IscCodes.op_create);
     Xdr.Write(0);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     Xdr.WriteBuffer(Encoding.UTF8.GetBytes(database));
     Xdr.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 2
0
 protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_create);
     XdrStream.Write(0);
     if (AuthData != null)
     {
         dpb.Append(IscCodes.isc_dpb_specific_auth_data, AuthData);
     }
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     XdrStream.WriteBuffer(Encoding.UTF8.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 3
0
 protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     this.Write(IscCodes.op_create);
     this.Write(0);
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     this.WriteBuffer(Encoding.UTF8.GetBytes(database));
     this.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 4
0
 protected override void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     // Attach to the database
     this.Write(IscCodes.op_attach);
     this.Write(0);                                      // Database	object ID
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     this.WriteBuffer(Encoding.UTF8.GetBytes(database)); // Database	PATH
     this.WriteBuffer(dpb.ToArray());                    // DPB Parameter buffer
 }
Exemplo n.º 5
0
 protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     Xdr.Write(IscCodes.op_create);
     Xdr.Write(DatabaseObjectId);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     Xdr.WriteBuffer(Encoding.Default.GetBytes(database));
     Xdr.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 6
0
 protected virtual void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_attach);
     XdrStream.Write(0);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     XdrStream.WriteBuffer(Encoding2.Default.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArray());
 }
        protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
        {
            XdrStream.Write(IscCodes.op_create);
#warning Some constant for default database object ID
            XdrStream.Write(0);
            if (!string.IsNullOrEmpty(Password))
            {
                dpb.Append(IscCodes.isc_dpb_password, Password);
            }
            XdrStream.WriteBuffer(Encoding.UTF8.GetBytes(database));
            XdrStream.WriteBuffer(dpb.ToArray());
        }
Exemplo n.º 8
0
        private static void CreateDatabaseImpl(string connectionString, int pageSize = 4096, bool forcedWrites = true, bool overwrite = false)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                dpb.Append(IscCodes.isc_dpb_version1);
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
                if (!string.IsNullOrEmpty(options.UserID))
                {
                    dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
                }
                if (options.Charset.Length > 0)
                {
                    Charset charset = Charset.GetCharset(options.Charset);
                    if (charset == null)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                    }
                }
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));
                dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                using (FbConnectionInternal db = new FbConnectionInternal(options))
                {
                    db.CreateDatabase(dpb);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 9
0
        private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
        {
            DatabaseParameterBuffer dpb = db.CreateDatabaseParameterBuffer();

            dpb.Append(IscCodes.isc_dpb_version1);
            dpb.Append(IscCodes.isc_dpb_dummy_packet_interval,
                       new byte[] { 120, 10, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_sql_dialect,
                       new byte[] { Convert.ToByte(options.Dialect), 0, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);
            if (options.Role != null && options.Role.Length > 0)
            {
                dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
            }
            dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);
            dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
            dpb.Append(IscCodes.isc_dpb_password, options.Password);

            return(dpb);
        }
        private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
        {
            var dpb = new DatabaseParameterBuffer();

            dpb.Append(IscCodes.isc_dpb_version1);
            dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);
            if (options.DbCachePages > 0)
            {
                dpb.Append(IscCodes.isc_dpb_num_buffers, options.DbCachePages);
            }
            if (!string.IsNullOrEmpty(options.UserID))
            {
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
            }
            if (!string.IsNullOrEmpty(options.Role))
            {
                dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
            }
            dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);
            dpb.Append(IscCodes.isc_dpb_process_id, GetProcessId());
            dpb.Append(IscCodes.isc_dpb_process_name, GetProcessName());
            dpb.Append(IscCodes.isc_dpb_client_version, GetClientVersion());
            if (options.NoDatabaseTriggers)
            {
                dpb.Append(IscCodes.isc_dpb_no_db_triggers, 1);
            }
            if (options.NoGarbageCollect)
            {
                dpb.Append(IscCodes.isc_dpb_no_garbage_collect, (byte)0);
            }

            return(dpb);
        }
Exemplo n.º 11
0
 protected virtual void SendTrustedAuthToBuffer(DatabaseParameterBuffer dpb, byte[] authData)
 {
     dpb.Append(IscCodes.isc_dpb_trusted_auth, authData);
 }
Exemplo n.º 12
0
        public static void CreateDatabase(string connectionString, int pageSize, bool forcedWrites, bool overwrite)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, options.Password);

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });

                // Character set
                if (options.Charset.Length > 0)
                {
                    Charset charset = Charset.GetCharset(options.Charset);

                    if (charset == null)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                    }
                }

                // Forced writes
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));

                // Page	Size
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                // Create the new database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 13
0
        public static void CreateDatabase(Hashtable values)
        {
            bool overwrite  = false;
            int  index      = 0;
            byte dialect    = 3;
            int  serverType = 0;

            if (!values.ContainsKey("User") ||
                !values.ContainsKey("Password") ||
                !values.ContainsKey("Database"))
            {
                throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
            }

            if (values.ContainsKey("ServerType"))
            {
                serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
            }

            if (!values.ContainsKey("DataSource"))
            {
                values.Add("DataSource", "localhost");
            }

            if (!values.ContainsKey("Port"))
            {
                values.Add("Port", 3050);
            }

            if (values.ContainsKey("Dialect"))
            {
                dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
            }

            if (dialect < 1 || dialect > 3)
            {
                throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
            }

            if (values.ContainsKey("Overwrite"))
            {
                overwrite = (bool)values["Overwrite"];
            }

            try
            {
                // Configure Attachment
                FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

                csb.DataSource = values["DataSource"].ToString();
                csb.UserID     = values["User"].ToString();
                csb.Password   = values["Password"].ToString();
                csb.Database   = values["Database"].ToString();
                csb.Port       = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
                csb.ServerType = serverType;

                FbConnectionString options = new FbConnectionString(csb);

                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, values["User"].ToString());

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { dialect, 0, 0, 0 });

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

                // Character set
                if (values.ContainsKey("Charset"))
                {
                    index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

                    if (index == -1)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(
                            IscCodes.isc_dpb_set_db_charset,
                            Charset.SupportedCharsets[index].Name);
                    }
                }

                // Page	Size
                if (values.ContainsKey("PageSize"))
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
                }

                // Forced writes
                if (values.ContainsKey("ForcedWrite"))
                {
                    dpb.Append(IscCodes.isc_dpb_force_write,
                               (short)((bool)values["ForcedWrite"] ? 1 : 0));
                }

                if (!overwrite)
                {
                    try
                    {
                        // Check if	the	database exists
                        FbConnectionInternal check = new FbConnectionInternal(options);

                        check.Connect();
                        check.Disconnect();

                        IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

                        throw new FbException(ex.Message, ex);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                // Create the new database
                FbConnectionInternal c = new FbConnectionInternal(options);
                c.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 14
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="CreateDatabase(System.String,System.Int32,System.Boolean,System.Boolean)"]/*'/>
        public static void CreateDatabase(
            string connectionString, int pageSize, bool forcedWrites, bool overwrite)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, options.Password);

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

                // Character set
                if (options.Charset.Length > 0)
                {
                    int index = Charset.SupportedCharsets.IndexOf(options.Charset);

                    if (index == -1)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(
                            IscCodes.isc_dpb_set_db_charset,
                            Charset.SupportedCharsets[index].Name);
                    }
                }

                // Page	Size
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                // Forced writes
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));

                if (!overwrite)
                {
                    // Check if	the	database exists
                    FbConnectionInternal c = new FbConnectionInternal(options);

                    try
                    {
                        c.Connect();
                        c.Disconnect();

                        IscException ex = new IscException(IscCodes.isc_db_or_file_exists);
                        throw new FbException(ex.Message, ex);
                    }
                    catch (FbException ex)
                    {
                        if (ex.ErrorCode != 335544344)
                        {
                            throw;
                        }
                    }
                }

                // Create the new database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 15
0
        public int Connect(string database, string user, string password, string hostName)
        {
            int    port       = 3050;
            string dataSource = hostName;
            string dbPath     = database;

            try
            {
                string connectionString =
                    String.Format(
                        "{0}={1};{2}={3};{4}={5};{6}={7};{8}",
                        "DataSource", hostName,
                        "Database", database,
                        "User", user,
                        "Password", password,
                        this.connectionOptions);

                FbConnectionString cs = new FbConnectionString();
                cs.ConnectionString = connectionString;

                Regex r = new Regex(@"(?<datasource>.*)/(?<port>[0-9]*):(?<database>.*)", RegexOptions.ExplicitCapture);

                Match m = r.Match(database);

                if (m != null)
                {
                    if (m.Groups["datasource"].Success)
                    {
                        dataSource = m.Groups["datasource"].Value;
                    }

                    if (m.Groups["port"].Success)
                    {
                        port = Int32.Parse(m.Groups["port"].Value);
                    }

                    if (m.Groups["database"].Success)
                    {
                        dbPath = m.Groups["database"].Value;
                    }
                }

                //  Create database instance
                this.db = ClientFactory.CreateDatabase(cs.ServerType);

                // Build DPB
                DatabaseParameterBuffer dpb = this.db.CreateDatabaseParameterBuffer();

                dpb.Append(IscCodes.isc_dpb_version1);
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval,
                           new byte[] { 120, 10, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_sql_dialect,
                           new byte[] { Convert.ToByte(cs.Dialect), 0, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_lc_ctype, cs.Charset);
                if (cs.RoleName != null)
                {
                    if (cs.RoleName.Length > 0)
                    {
                        dpb.Append(IscCodes.isc_dpb_sql_role_name, cs.RoleName);
                    }
                }
                dpb.Append(IscCodes.isc_dpb_user_name, user);
                dpb.Append(IscCodes.isc_dpb_password, password);

                // Perform attach
                this.db.Attach(dpb, dataSource, port, dbPath);
            }
            catch (IscException e)
            {
                this.lastError = e;
            }

            return(this.GetErrorCode());
        }