Example #1
0
 public override System.Data.Common.DbParameter get_par(schema_field col)
 {
     if (col.OriginalType == "datetime")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.DateTime));
     }
     else if (col.OriginalType == "datetime2")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.DateTime2));
     }
     else if (col.OriginalType == "int")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Int));
     }
     else if (col.OriginalType == "smallint")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.SmallInt));
     }
     else if (col.OriginalType == "bigint")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.BigInt));
     }
     else if (col.OriginalType == "long")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.BigInt));
     }
     else if (col.OriginalType == "char" || col.OriginalType == "varchar" || col.OriginalType == "nchar" || col.OriginalType == "nvarchar")
     {
         return(col.MaxLength.Value > 0 ? new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.VarChar, col.MaxLength.Value)
     : new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.VarChar));
     }
     else if (col.OriginalType == "text" || col.OriginalType == "ntext")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Text));
     }
     else if (col.OriginalType == "xml")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Xml));
     }
     else if (col.OriginalType == "bit")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Bit));
     }
     else if (col.OriginalType == "decimal" || col.OriginalType == "numeric")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Decimal));
     }
     else if (col.OriginalType == "float" || col.OriginalType == "real" || col.OriginalType == "money" || col.OriginalType == "smallmoney")
     {
         return(new SqlParameter("@" + col.Name.ToUpper(), SqlDbType.Float));
     }
     else
     {
         throw new Exception("tipo di dati '" + col.OriginalType + "' non supportato per l'importazione dei dati");
     }
 }
Example #2
0
 public static XmlNode create_field_node(XmlDocument doc, schema_field fld)
 {
     return(xmlDoc.set_attrs(doc.CreateElement("col"), new Dictionary <string, string>()
     {
         { "name", fld.Name }, { "nameupper", fld.Name.ToUpper() }
         , { "type", fld.OriginalType }, { "autonumber", fld.AutoNumber ? "true" : "" }
         , { "nullable", fld.Nullable ? "true" : "" }, { "default", fld.Default }
         , { "maxlength", fld.MaxLength.HasValue ? fld.MaxLength.Value.ToString() : "" }
         , { "numprec", fld.NumPrecision.HasValue ? fld.NumPrecision.Value.ToString() : "" }
         , { "numscale", fld.NumScale.HasValue ? fld.NumScale.Value.ToString() : "" }
     }));
 }
Example #3
0
        public XmlNode set_field(string table, schema_field new_field)
        {
            XmlNode col_node = field_node(table, new_field.Name);

            if (col_node == null)
            {
                return(xmlDoc.add_node(table_node(table).SelectSingleNode("cols"), create_field_node(new_field)));
            }

            XmlNode res = xmlDoc.add_node(table_node(table).SelectSingleNode("cols"), create_field_node(new_field), col_node);

            col_node.ParentNode.RemoveChild(col_node);
            return(res);
        }
Example #4
0
        public void xmldata_to_table(db_schema db, string table)
        {
            List <schema_field> cols = db.table_fields(table);

            // cols
            using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/data")) {
                if (xr.ReadUntilMatch())
                {
                    while (xr.MoveToNextAttribute())
                    {
                        schema_field field = findField(cols, xr.Value);
                        if (field == null)
                        {
                            continue;
                        }
                        field.AttrName = xr.Name;
                    }
                }
                else
                {
                    throw new Exception("la struttura xml del file data della tabella '" + table + "' non è corretta");
                }
            }

            // insert rows
            bool identity = db.type == dbType.sqlserver && cols.FirstOrDefault(x => x.AutoNumber) != null;

            if (identity)
            {
                db.set_identity(table, true);
            }
            try {
                using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/rows/row")) {
                    string header = string.Format("INSERT INTO {0} ({1})", table, string.Join(", ", cols.Select(x => "[" + x.Name + "]")));
                    while (xr.ReadUntilMatch())
                    {
                        db.exec(header + " VALUES (" + string.Join(", ", cols.Select(x => db.val_toqry(xr[x.AttrName], x.TypeField, type, _nullxml))) + ")");
                    }
                }
            }
            finally { if (identity)
                      {
                          db.set_identity(table, false);
                      }
            }
        }
Example #5
0
        public override System.Data.Common.DbParameter get_par(schema_field col)
        {
            OleDbParameter result = null;

            if (col.OriginalType == "datetime")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.DBDate);
            }
            else if (col.OriginalType == "int" || col.OriginalType == "smallint")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.Integer);
            }
            else if (col.OriginalType == "bigint" || col.OriginalType == "long")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.BigInt);
            }
            else if (col.OriginalType == "char" || col.OriginalType == "varchar" || col.OriginalType == "text" ||
                     col.OriginalType == "nchar" || col.OriginalType == "nvarchar" || col.OriginalType == "ntext")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.VarChar, col.MaxLength.Value);
            }
            else if (col.OriginalType == "bit")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.Boolean);
            }
            else if (col.OriginalType == "float" || col.OriginalType == "real" || col.OriginalType == "decimal" || col.OriginalType == "money" ||
                     col.OriginalType == "smallmoney" || col.OriginalType == "numeric")
            {
                result = new OleDbParameter("@" + col.Name.ToUpper(), OleDbType.Double);
            }
            else
            {
                throw new Exception("tipo di dati '" + col.OriginalType + "' non supportato per l'importazione dei dati");
            }

            return(result);
        }
Example #6
0
 public override void alter_field(schema_field tblfield, string tableName)
 {
     exec("ALTER TABLE [" + tableName + "] ALTER COLUMN "
          + tblfield.getFieldAccess());
 }
Example #7
0
 public override void drop_field(schema_field field, string tableName)
 {
     exec("ALTER TABLE [" + tableName + "] DROP COLUMN [" + field.Name + "]");
 }
Example #8
0
 public override void add_field(schema_field tblField, string tableName)
 {
     exec("ALTER TABLE [" + tableName + "] ADD "
          + tblField.getFieldAccess());
 }
Example #9
0
 public override void upd_field(schema_field tblField, string tableName)
 {
     exec("ALTER TABLE " + tableName + " ALTER COLUMN " + tblField.getFieldSqlServer());
 }
Example #10
0
 public XmlNode create_field_node(schema_field fld)
 {
     return(create_field_node(_doc.doc, fld));
 }
Example #11
0
        public string val(string field)
        {
            schema_field sfld = get_field(field);

            return(_xr[sfld.AttrName] != null && _xr[sfld.AttrName] != db_schema.null_value ? _xr[sfld.AttrName] : null);
        }
Example #12
0
        public string val_to_qry(string field, db_schema db_ref)
        {
            schema_field sfld = get_field(field);

            return(db_ref.val_toqry(_xr[sfld.AttrName], sfld.TypeField, db_schema.null_value));
        }
Example #13
0
 public virtual void alter_field(schema_field tblfield, string tableName)
 {
     throw new Exception("il provider " + _dbType.ToString() + " non supporta la funzionalità alterFieldTable");
 }
Example #14
0
 public virtual void drop_field(schema_field field, string tableName)
 {
     throw new Exception("il provider " + _dbType.ToString() + " non supporta la funzionalità dropFieldToTable");
 }
Example #15
0
 public virtual System.Data.Common.DbParameter get_par(schema_field col)
 {
     throw new Exception("il provider " + _dbType.ToString() + " non supporta la funzionalità getParameter");
 }