Beispiel #1
0
        public override string GetLastInsertIdSqlSuffix <T>()
        {
            var modelDef = GetModel(typeof(T));
            var pkName   = NamingStrategy.GetColumnName(modelDef.PrimaryKey.FieldName);

            return($" RETURNING \"{pkName}\"");
        }
Beispiel #2
0
        protected override string ToCreateIndexStatement(bool isUnique, string indexName, ModelDefinition modelDef, string fieldName,
                                                         bool isCombined = false, FieldDefinition fieldDef = null)
        {
            var fieldNames = fieldName.Split(',')
                             .Map(x => NamingStrategy.GetColumnName(x.LeftPart(' ')));

            return($"CREATE {(isUnique ? "UNIQUE" : "")} INDEX {indexName} ON {GetQuotedTableName(modelDef)} ({string.Join(",", fieldNames.ToArray())}); \n");
        }
        protected override string ToCreateIndexStatement(bool isUnique, string indexName, ModelDefinition modelDef, string fieldName,
                                                         bool isCombined = false, FieldDefinition fieldDef = null)
        {
            var fieldNames = fieldName.Split(',')
                             .Map(x => NamingStrategy.GetColumnName(x.SplitOnFirst(' ')[0]));

            return(string.Format("CREATE {0} INDEX {1} ON {2} ({3}); \n",
                                 isUnique ? "UNIQUE" : "",
                                 indexName,
                                 GetQuotedTableName(modelDef),
                                 string.Join(",", fieldNames.ToArray())));
        }
        public override string GetLastInsertIdSqlSuffix <T>()
        {
            if (SelectIdentitySql == null)
            {
                throw new NotImplementedException("Returning last inserted identity is not implemented on this DB Provider.");
            }

            if (UseReturningForLastInsertId)
            {
                var modelDef = GetModel(typeof(T));
                var pkName   = NamingStrategy.GetColumnName(modelDef.PrimaryKey.FieldName);
                return($" RETURNING \"{pkName}\"");
            }

            return("; " + SelectIdentitySql);
        }
Beispiel #5
0
        public override string GetColumnDefinition(FieldDefinition fieldDef)
        {
            if (fieldDef.PropertyInfo?.HasAttributeCached <TextAttribute>() == true)
            {
                var sql = StringBuilderCache.Allocate();
                sql.AppendFormat("{0} {1}", GetQuotedName(NamingStrategy.GetColumnName(fieldDef.FieldName)), TextColumnDefinition);
                sql.Append(fieldDef.IsNullable ? " NULL" : " NOT NULL");
                return(StringBuilderCache.ReturnAndFree(sql));
            }

            var ret = base.GetColumnDefinition(fieldDef);

            if (fieldDef.IsRowVersion)
            {
                return($"{ret} DEFAULT 1");
            }

            return(ret);
        }
Beispiel #6
0
        public override long InsertAndGetLastInsertId <T>(IDbCommand dbCmd)
        {
            if (SelectIdentitySql == null)
            {
                throw new NotImplementedException("Returning last inserted identity is not implemented on this DB Provider.");
            }

            if (UseReturningForLastInsertId)
            {
                var modelDef = GetModel(typeof(T));
                var pkName   = NamingStrategy.GetColumnName(modelDef.PrimaryKey.FieldName);
                dbCmd.CommandText += " RETURNING " + pkName;
            }
            else
            {
                dbCmd.CommandText += "; " + SelectIdentitySql;
            }

            return(dbCmd.ExecLongScalar());
        }
 public override string GetQuotedColumnName(string fieldName)
 {
     return(Quote(NamingStrategy.GetColumnName(fieldName)));
 }
Beispiel #8
0
 public override string GetQuotedColumnName(string columnName)
 {
     return(string.Format("`{0}`", NamingStrategy.GetColumnName(columnName)));
 }
 /// <summary>Gets quoted column name.</summary>
 /// <param name="columnName">Name of the column.</param>
 /// <returns>The quoted column name.</returns>
 public virtual string GetQuotedColumnName(string columnName)
 {
     return($"{EscapeChar}{NamingStrategy.GetColumnName(columnName)}{EscapeChar}");
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="columnName"></param>
 /// <returns></returns>
 public virtual string GetQuotedColumnName(string columnName)
 {
     return(GetQuotedName(NamingStrategy.GetColumnName(columnName)));
 }