GENERATOR name in Firebird

Topics: Developer Forum, Project Management Forum, User Forum
Feb 9, 2010 at 11:14 AM

Hi,

i'm newbie in DbEntry. I see a great product which is very helpful for me, although i've a bit question. Is there any way to define my own generator name in PK fields?

I've seen in Firebird.cs, the method GetSelectSequenceSql which always use the pattern GEN_{0}_ID to call the generator in Firebird, it would be very helpful could define an alternative name instead a fixed pattern. I've a legacy database which their generators are named using GEN_{tableName}_ID sometimes while other times they are named {tableName}_GEN_ID

Any help would be apreciated.

Thanks in advance

Juan Pedro Rubio
jprubio@inditar.com
http://www.inditar.com

 

Coordinator
Feb 9, 2010 at 1:46 PM

Sorry, DbEntry only supports fixed pattern for generator and there is no plan to add this feature.

For your case, I think maybe you can just rename those generators which are not follow this pattern when you upgrade your project.

Feb 9, 2010 at 3:51 PM

Thanks for you quick reply,

i have made some changes in Firebird.cs in order to get desired behaviour. I've attached you these changes to make them public if you want.

 

using Lephone.Data.SqlEntry;
using Lephone.Util.Logging;
using Lephone.Data.Common;
using Lephone.Util.Setting;

namespace Lephone.Data.Dialect
{
    public class Firebird : SequencedDialect
    {

        public string FirebirdGenPattern;

        public Firebird()
        {
            FirebirdGenPattern = ConfigHelper.DefaultSettings.GetValue("FirebirdGenPattern", "GEN_{0}_ID");

            TypeNames[DataType.Boolean] = "SMALLINT";
            TypeNames[DataType.DateTime] = "TIMESTAMP";
            TypeNames[DataType.String] = "BLOB SUB_TYPE 1";
            TypeNames[DataType.Binary] = "BLOB SUB_TYPE 0";
            TypeNames[typeof(byte[])] = "BLOB";
            TypeNames[DataType.Double] = "DOUBLE PRECISION";
        }

        public override string DbNowString
        {
            get { return "CURRENT_TIMESTAMP"; }
        }

        public override DbStructInterface GetDbStructInterface()
        {
            return new DbStructInterface(null, new[] { null, null, null, "TABLE" }, null, null, null);
        }

        protected override string GetSelectSequenceSql(string TableName)
        {
            return string.Format("SELECT GEN_ID(" + FirebirdGenPattern + ", 1) FROM RDB$DATABASE", TableName.ToUpper());
            
        }

        public override bool NeedCommitCreateFirst
        {
            get { return true; }
        }

        public override bool SupportDirctionOfEachColumnInIndex
        {
            get { return false; }
        }

        public override string GetUnicodeTypeString(string AsciiTypeString)
        {
            return AsciiTypeString + " CHARACTER SET UNICODE_FSS";
        }

        public override string IdentityColumnString
        {
            get { return "NOT NULL"; }
        }

        public override string GetCreateSequenceString(string TableName)
        {
            return string.Format("CREATE GENERATOR " + FirebirdGenPattern + ";\n", TableName.ToUpper());
        }

        protected override string QuoteSingle(string name)
        {
            return base.QuoteSingle(name.ToUpper());
        }

        public override string NullString
        {
            get { return ""; }
        }

        public override bool ExecuteEachLine
        {
            get { return true; }
        }

        public override void ExecuteDropSequence(DataProvider dp, string TableName)
        {
            string sql = string.Format("DROP GENERATOR " + FirebirdGenPattern + ";\n", TableName.ToUpper());
            Logger.SQL.Trace(sql);
            dp.ExecuteNonQuery(sql);
        }

        protected override SqlStatement GetPagedSelectSqlStatement(Builder.SelectStatementBuilder ssb)
        {
            SqlStatement Sql = base.GetNormalSelectSqlStatement(ssb);
            Sql.SqlCommandText = string.Format("{0} ROWS {1} TO {2}",
                Sql.SqlCommandText, ssb.Range.StartIndex, ssb.Range.EndIndex);
            return Sql;
        }

        public override string GenIndexName(string n)
        {
            return GenIndexName(n, 31);
        }

        protected override string GetLengthStringForBlob(int Length)
        {
            if(Length < 80)
            {
                return base.GetLengthStringForBlob(Length);
            }
            return "";
        }
    }
}



In your app.config (or web.config) add this key:


<add key="FirebirdGenPattern" value="{0}_ID_GEN"/>

with the pattern you want


Thanks again. Best regards

Juan Pedro Rubio
www.inditar.com