Ejemplo n.º 1
0
        public override string buildCreateTableStatement(ATable tbl)
        {
            // TODO Write code to compile this table object into sql statements.
            string sqlstr = "create table " + tbl.name + " (";

            // build the defs here
            string typeString = ""; string collectedModifiers = "";
            foreach (AField field in tbl.getFieldList())
            {
                typeString = this._dbObj.GetDatabaseProvider().fieldToTypeStr(field);
                //typeString = SQLConsole.Data.ProviderConverters.TypeConverters.FieldToTypeString(field, this._dbObj.GetDatabaseConnector().getDBType());
                if (this._dbObj.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL)
                {
                    // Since mysql puts keys at the end of a statement we must collect them here.
                    if (field.modifiers != null)
                    {
                        foreach (ABSTRACTFIELDMODIFIERS mod in field.modifiers)
                        {
                            if (mod == ABSTRACTFIELDMODIFIERS.PrimaryKey)
                            {
                                collectedModifiers += " PRIMARY KEY(" + field.name + "), ";
                            }
                            else if (mod == ABSTRACTFIELDMODIFIERS.IndexKey)
                            {
                                collectedModifiers += " KEY(" + field.name + "), ";
                            }
                            else if (mod == ABSTRACTFIELDMODIFIERS.ForeignKey)
                            {
                                string foreignPrimaryKey = this._dbObj.GetTableCache().getCachedTable((string)field.value).getPrimaryKey().name;
                                collectedModifiers += " FOREIGN KEY(" + field.name + ") REFERENCES " + field.value + "(" + foreignPrimaryKey + "), ";
                            }
                        }
                    }
                }
                sqlstr += field.name + " " + typeString + ", ";
            }

            sqlstr += collectedModifiers;
            sqlstr = sqlstr.Trim();
            if (sqlstr.Substring(sqlstr.Length - 1) == ",")
            {
                sqlstr = sqlstr.Substring(0, sqlstr.Length - 1);
            }
            sqlstr += ");";
            return sqlstr;
        }
Ejemplo n.º 2
0
        public override string buildCreateTableStatement(ATable tbl)
        {
            // TODO Write code to compile this table object into sql statements.
            string sqlstr = "create table " + tbl.name + " (";

            // build the defs here
            string typeString = ""; string collectedModifiers = "";
            foreach (AField field in tbl.getFieldList())
            {
                //typeString = SQLConsole.Data.ProviderConverters.TypeConverters.FieldToTypeString(field, this._dbObj.GetDatabaseConnector().getDBType());
                typeString = this._dbObj.GetDatabaseProvider().fieldToTypeStr(field);
                sqlstr += field.name + " " + typeString + ", ";
            }

            sqlstr += collectedModifiers;
            sqlstr = sqlstr.Trim();
            if (sqlstr.Substring(sqlstr.Length - 1) == ",")
            {
                sqlstr = sqlstr.Substring(0, sqlstr.Length - 1);
            }
            sqlstr += ");";
            return sqlstr;
        }
Ejemplo n.º 3
0
        public void InsertIfAbsent(ATable row, string[] except)
        {
            string where = "";
            foreach (AField f in row.getFieldList())
            {
                bool wordBanned = Array.Exists(except, new Predicate<string>(
                    delegate(String str)
                    {
                        if (str == f.name) return true;
                        return false;
                    }
                ));
                if(!wordBanned)
                where = (where == "" ? f.name + "='" + f.value + "'" : where + " and " + f.name + "='" + f.value + "'");
            }
            object check = this.getSingleResult("select * from " + row.name + " where " + where);

            if (check == null)
            {
                QueryBuilder qbl = this.CreateQueryBuilder();
                qbl.setType(ABSTRACTQUERYTYPES.InsertQuery);
                qbl.addSource(row.name);
                qbl.setFieldList(row.getFieldList());
                string sql = qbl.Compile();
            }
        }
Ejemplo n.º 4
0
        public void InsertIfAbsent(ATable row)
        {
            string where = "";
            foreach (AField f in row.getFieldList())
            {
                where = (where==""?f.name+"='"+f.value+"'":where + " and " + f.name+"='"+f.value+"'");
            }
            object check = this.getSingleResult("select * from " + row.name + " where " + where);

            if (check == null)
            {
                QueryBuilder qbl = this.CreateQueryBuilder();
                qbl.setType(ABSTRACTQUERYTYPES.InsertQuery);
                qbl.addSource(row.name);
                qbl.setFieldList(row.getFieldList());
                string sql = qbl.Compile();
            }
        }