Example #1
0
        public long exec(db_schema conn, string name_cmd = "", page_cls pg_parse = null, Dictionary <string, string> fields = null, DataRow row = null)
        {
            long result = 0;

            // ciclo comandi
            if (fields == null)
            {
                fields = new Dictionary <string, string>();
            }
            foreach (db_script_cmd cmd in cmds(name_cmd))
            {
                if (cmd.type == db_script_cmd.cmd_type.sql)
                {
                    string sql = pg_parse == null ? cmd.text : pg_parse.page.parse(cmd.text, "", fields, row);
                    if (cmd.attr("setkey") != "")
                    {
                        long key = conn.exec(sql, true); result++;
                        if (!fields.ContainsKey(cmd.attr("setkey")))
                        {
                            fields.Add(cmd.attr("setkey"), key.ToString());
                        }
                        else
                        {
                            fields[cmd.attr("setkey")] = key.ToString();
                        }
                    }
                    else
                    {
                        result += conn.exec(sql);
                    }
                }
                else if (cmd.type == db_script_cmd.cmd_type.init_tables)
                {
                    conn.upgrade_data(new db_xml(new xmlDoc(conn.parse_dbexpression(conn.schema_path, conn.parse_dbexpression(cmd.attr("ver"))))
                                                 , conn.parse_dbexpression(conn.meta_path, conn.parse_dbexpression(cmd.attr("ver")))), false, true, cmd.attr("notes"));
                }
                else if (cmd.type == db_script_cmd.cmd_type.init_table)
                {
                    if (conn.exist_table(cmd.attr("table")))
                    {
                        conn.drop_table(cmd.attr("table"));
                    }
                    conn.create_table(conn.schema.table_node(cmd.attr("table")));
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_tables)
                {
                    conn.dropTables();
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_functions)
                {
                    conn.dropFunctions();
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_procedures)
                {
                    conn.dropProcedures();
                }
                else if (cmd.type == db_script_cmd.cmd_type.exec_script)
                {
                    conn.exec_script(cmd.attr("name"));
                }
                else if (cmd.type == db_script_cmd.cmd_type.for_each_table)
                {
                    for_each_table(conn, cmd);
                }
                else if (cmd.type == db_script_cmd.cmd_type.set_info)
                {
                    conn.setInfo(cmd.attr("name"), conn.parse_dbexpression(cmd.attr("value")), 0, cmd.attr("notes"));
                }
            }

            return(result);
        }