Beispiel #1
0
        public static void Main(string[] args)
        {
            Spartacus.Database.Generic v_db;
            System.Data.DataTable v_table;

            Console.WriteLine("Exemplo PostgreSQL usando Spartacus");
            Console.WriteLine();

            try
            {
                // 1) informar qual SGBD e dados de conexão
                v_db = new Spartacus.Database.Postgresql("127.0.0.1", "lugares", "postgres", "knightnote");

                // 2) fazer a consulta e jogar os resultados no DataTable
                v_table = v_db.Query("select * from estados", "ESTADOS");

                // 3) usar o DataTable (imprimir na tela)
                foreach (System.Data.DataColumn c in v_table.Columns)
                    Console.Write("{0}  ", c.ColumnName);
                Console.WriteLine();
                foreach (System.Data.DataRow r in v_table.Rows)
                {
                    foreach (System.Data.DataColumn c in v_table.Columns)
                        Console.Write("{0}      ", r[c].ToString());
                    Console.WriteLine();
                }
            }
            catch (Spartacus.Database.Exception exc)
            {
                Console.WriteLine(exc.v_message);
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Spartacus.Utils.ProgressEventClass v_progress;
            Spartacus.Utils.ErrorEventClass v_error;
            Spartacus.Database.Command v_cmd;
            Spartacus.Database.Generic database = new Spartacus.Database.Postgresql("192.168.56.2","cotacoes","psotgres","Crc19D98C");

            v_progress = new Spartacus.Utils.ProgressEventClass();
            v_error = new Spartacus.Utils.ErrorEventClass();

            int[] v_exp = { 1, 5, 10, 50, 100, 250, 500, 750, 1000, 2000, 3000 };
            System.Diagnostics.Stopwatch v_watch = new System.Diagnostics.Stopwatch();
            foreach (int v_bloco in v_exp)
            {
                database.v_blocksize = v_bloco;
                v_watch.Start;

                database.Open();
                database.TransferFromFile(
                    "Caminho Do Arquivo Aqui",
                    ";",
                    "",
                    false,
                    System.Text.Encoding.UTF8,
                    "cotacoes", // tabela existe
                    "(dia,codmoeda,tipomoeda,siglamoeda,taxacompra,taxavenda,parcompra,parvenda)",
                    v_cmd,
                    v_progress,
                    v_error
                );
                database.Close();

                v_watch.Stop;
                Console.WriteLine("Tamanho de bloco = {0}, tempo total = {1}", v_bloco, v_watch.Elapsed);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OmniDB.Database.PostgreSQL"/> class.
        /// </summary>
        /// <param name="p_server">Connection address.</param>
        /// <param name="p_port">Connection port.</param>
        /// <param name="p_service">Database name.</param>
        /// <param name="p_user">Database user.</param>
        /// <param name="p_password">Database password.</param>
        /// <param name="p_schema">Schema.</param>
        public PostgreSQL(string p_conn_id, string p_server, string p_port, string p_service, string p_user, string p_password, string p_schema)
            : base("postgresql", p_conn_id)
        {
            v_server          = p_server;
            v_port            = p_port;
            v_service         = p_service;
            v_user            = p_user;
            v_has_schema      = true;
            v_has_update_rule = true;

            v_default_string = "text";

            v_can_rename_table     = true;
            v_rename_table_command = "alter table #p_table_name# rename to #p_new_table_name#";

            v_create_pk_command     = "constraint #p_constraint_name# primary key (#p_columns#)";
            v_create_fk_command     = "constraint #p_constraint_name# foreign key (#p_columns#) references #p_r_table_name# (#p_r_columns#) #p_delete_update_rules#";
            v_create_unique_command = "constraint #p_constraint_name# unique (#p_columns#)";

            v_can_alter_type     = true;
            v_alter_type_command = "alter table #p_table_name# alter #p_column_name# type #p_new_data_type#";

            v_can_alter_nullable    = true;
            v_set_nullable_command  = "alter table #p_table_name# alter #p_column_name# drop not null";
            v_drop_nullable_command = "alter table #p_table_name# alter #p_column_name# set not null";

            v_can_rename_column     = true;
            v_rename_column_command = "alter table #p_table_name# rename #p_column_name# to #p_new_column_name#";

            v_can_add_column     = true;
            v_add_column_command = "alter table #p_table_name# add column #p_column_name# #p_data_type# #p_nullable#";

            v_can_drop_column     = true;
            v_drop_column_command = "alter table #p_table_name# drop #p_column_name#";

            v_can_add_constraint = true;
            v_add_pk_command     = "alter table #p_table_name# add constraint #p_constraint_name# primary key (#p_columns#)";
            v_add_fk_command     = "alter table #p_table_name# add constraint #p_constraint_name# foreign key (#p_columns#) references #p_r_table_name# (#p_r_columns#) #p_delete_update_rules#";
            v_add_unique_command = "alter table #p_table_name# add constraint #p_constraint_name# unique (#p_columns#)";

            v_can_drop_constraint = true;
            v_drop_pk_command     = "alter table #p_table_name# drop constraint #p_constraint_name#";
            v_drop_fk_command     = "alter table #p_table_name# drop constraint #p_constraint_name#";
            v_drop_unique_command = "alter table #p_table_name# drop constraint #p_constraint_name#";

            v_create_index_command        = "create #p_uniqueness# index #p_index_name# on #p_table_name# (#p_columns#)";
            v_create_index_command        = "create index #p_index_name# on #p_table_name# (#p_columns#)";
            v_create_unique_index_command = "create unique index #p_index_name# on #p_table_name# (#p_columns#)";

            v_drop_index_command = "drop index #p_schema_name#.#p_index_name#";

            v_update_rules = new System.Collections.Generic.List <string> ();
            v_delete_rules = new System.Collections.Generic.List <string> ();

            v_delete_rules.Add("");
            v_delete_rules.Add("NO ACTION");
            v_delete_rules.Add("RESTRICT");
            v_delete_rules.Add("SET NULL");
            v_delete_rules.Add("SET DEFAULT");
            v_delete_rules.Add("CASCADE");

            v_update_rules.Add("");
            v_update_rules.Add("NO ACTION");
            v_update_rules.Add("RESTRICT");
            v_update_rules.Add("SET NULL");
            v_update_rules.Add("SET DEFAULT");
            v_update_rules.Add("CASCADE");

            v_trim_function = "trim";

            v_transfer_block_size = new System.Collections.Generic.List <uint> ();
            v_transfer_block_size.Add(50);
            v_transfer_block_size.Add(100);
            v_transfer_block_size.Add(200);
            v_transfer_block_size.Add(400);

            if (p_schema == "")
            {
                v_schema = "public";
            }
            else
            {
                v_schema = p_schema;
            }

            v_connection = new Spartacus.Database.Postgresql(p_server, p_port, p_service, p_user, p_password);
            v_connection.v_execute_security = false;

            v_has_functions  = true;
            v_has_procedures = false;
        }