Esempio n. 1
0
        /// <summary>
        /// Build a OdbcConnection String Based On DataSource Properties, If An Connection String Is Already Set Then it will that
        /// </summary>
        /// <returns>connection string</returns>
        private static string GetOdbcConnectionString(DataSourceDb datasource)
        {
            var IntegratedSecurity = datasource.IntegratedSecurity;
            var ConnectionString   = datasource.ConnectionString;
            var UserName           = datasource.UserName;
            var Password           = datasource.Password;
            var Server             = datasource.Server;
            var Database           = datasource.Database;

            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(ConnectionString))
            {
                return(ConnectionString);
            }
            //   if (!string.IsNullOrEmpty(DSN) && string.IsNullOrEmpty(UserName) && string.IsNullOrEmpty(Password)) return $"DSN={DSN}";
            //
            //
            //
            //   if (!string.IsNullOrEmpty(Driver))
            //       sb.Append(Driver.EndsWith(";") ? $"{nameof(Driver)}=" + Driver : $"{nameof(Driver)}=" + Driver + ";");
            //   if (!string.IsNullOrEmpty(Server))
            //       sb.Append(Server.EndsWith(";") ? $"servername=" + Server : $"servername=" + Server + ";");
            //   if (Port != null)
            //       sb.Append(Server.EndsWith(";") ? $"port=" + Port.Value : $"port=" + Port.Value + ";");
            //   if (!string.IsNullOrEmpty(Database))
            //       sb.Append(Database.EndsWith(";") ? "Database=" + Database : "Database=" + Database + ";");
            //   if (!string.IsNullOrEmpty(UserName))
            //       sb.Append(UserName.EndsWith(";") ? "UserName="******"UserName="******";");
            //   if (!string.IsNullOrEmpty(Password))
            //       sb.Append(Password.EndsWith(";") ? "Password="******"Password="******";");
            //
            //   sb.Append(IntegratedSecurity ? "Integrated Security=True;" : "Integrated Security=False;");
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the SQL parameter list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="poco">The poco.</param>
        /// <returns>List&lt;DbParameter&gt;.</returns>
        public static List <DbParameter> BuildDbParameterList <T>(this IDataSourceDb database, T poco) where T : class
        {
            DataSourceDb db = database is DataSourceDb sourceDb ? sourceDb : new DataSourceDb(database.DBTYPE);

            var list = new List <DbParameter>()
            {
            };

            ExtFastMember.GetAdvanceMembers(poco).ForEach(delegate(AdvanceMember p)
            {
                var validation = DataValidation.IsValidBasedOnSqlColumnAttributes(p);
                if (!validation.Item1)
                {
                    throw new InvalidDataException(string.Join(Environment.NewLine, validation.Item2));
                }

                object parameterValue = DBNull.Value;
                if (p.SqlCustomAttritube.SerializableType != SerializableType.NONE)
                {
                    if (p.Member.Type == typeof(string))
                    {
                        // assuming the string is already serialize and the developer don't know how this library works smh
                        parameterValue = db.ObjectSqlHelper.ConvertToDatabaseValue(p.Member, p.Value);
                    }
                    else
                    {
                        if (p.Value == null)
                        {
                            parameterValue = DBNull.Value;
                        }
                        else
                        {
                            switch (p.SqlCustomAttritube.SerializableType)
                            {
                            case SerializableType.XML:
                                database.XmlSerializer.IsNullThrow(nameof(database.XmlSerializer),
                                                                   new BadCodeException(
                                                                       $"YOU FOOL!!! Your claiming the property {p.Member.Name} in the type {p.Member.Type.FullName} value is in XML Format but your not specifying how to deserialize/serialize it )"));
                                parameterValue = database.XmlSerializer.SerializeToString(p.Value);
                                break;

                            case SerializableType.JSON:
                                database.JsonSerializer.IsNullThrow(nameof(JsonSerializer),
                                                                    new BadCodeException(
                                                                        $"YOU FOOL!!! Your claiming the property {p.Member.Name} in the type {p.Member.Type.FullName} value is in JSON Format but your not specifying how to deserialize/serialize it )"));
                                parameterValue = database.JsonSerializer.SerializeToString(p.Value);
                                break;

                            case SerializableType.CSV:
                                database.CsvSerializer.IsNullThrow(nameof(database.CsvSerializer),
                                                                   new BadCodeException(
                                                                       $"YOU FOOL!!! Your claiming the property {p.Member.Name} in the type {p.Member.Type.FullName} value is in CSV Format but your not specifying how to deserialize/serialize it )"));
                                parameterValue = database.CsvSerializer.SerializeToString(p.Value);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            //parameterValue = $"'{parameterValue.ToString().Replace("'", @"\'")}'";
                        }
                    }
                }
                else
                {
                    parameterValue = db.ObjectSqlHelper.ConvertToDatabaseValue(p.Member, p.Value);
                }
                // var command = GetNewCommand();

                list.Add(db.GetNewParameter($"@{p.Member.Name}", parameterValue));
            });
            return(list);
        }