AddFunctions() public method

This takes a ResultSet containing two columns. Column 1 contains the function name, Column 2 the oid. It reads the entire ResultSet, loading the values into the function table. REMEMBER to close() the resultset after calling this!! Implementation note about function name lookups: PostgreSQL stores the function id's and their corresponding names in the pg_proc table. To speed things up locally, instead of querying each function from that table when required, a Dictionary is used. Also, only the function's required are entered into this table, keeping connection times as fast as possible. The org.postgresql.largeobject.LargeObject class performs a query upon it's startup, and passes the returned ResultSet to the addFunctions() method here. Once this has been done, the LargeObject api refers to the functions by name. Dont think that manually converting them to the oid's will work. Ok, they will for now, but they can change during development (there was some discussion about this for V7.0), so this is implemented to prevent any unwarranted headaches in the future.
public AddFunctions ( IDataReader rs ) : void
rs IDataReader ResultSet
return void
Ejemplo n.º 1
0
        /*
         * Constructs the LargeObject API.
         *
         * <p><b>Important Notice</b>
         * <br>This method should only be called by org.postgresql.Connection
         *
         * <p>There should only be one LargeObjectManager per Connection. The
         * org.postgresql.Connection class keeps track of the various extension API's
         * and it's advised you use those to gain access, and not going direct.
         */

        public LargeObjectManager(NpgsqlConnection conn)
        {
            // We need Fastpath to do anything
            // Now get the function oid's for the api
            //
            // This is an example of Fastpath.addFunctions();
            //
            //String sql;
            StringBuilder sql = null;

            try
            {
                sql = new StringBuilder();
                if (conn.PostgreSqlVersion > new Version(7, 3, 0))
                {
                    sql.Append("SELECT p.proname,p.oid ");
                    sql.Append(" FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n ");
                    sql.Append(" WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND (");
                }
                else
                {
                    sql.Append("SELECT proname,oid FROM pg_proc WHERE ");
                }
                sql.Append(" proname = 'lo_open'");
                sql.Append(" or proname = 'lo_close'");
                sql.Append(" or proname = 'lo_creat'");
                sql.Append(" or proname = 'lo_unlink'");
                sql.Append(" or proname = 'lo_lseek'");
                sql.Append(" or proname = 'lo_tell'");
                sql.Append(" or proname = 'loread'");
                sql.Append(" or proname = 'lowrite'");

                if (conn.PostgreSqlVersion > new Version(7, 3, 0))
                {
                    sql.Append(")");
                }

                using (IDbCommand cmd = new NpgsqlCommand(sql.ToString()))
                {
                    cmd.Connection = conn;

                    this.fp = new Fastpath(conn, conn.Connector.Stream);

                    using (IDataReader res = cmd.ExecuteReader())
                    {
                        if (res == null)
                        {
                            throw new NpgsqlException("postgresql.lo.init");
                        }


                        fp.AddFunctions(res);
                    }
                }
            }
            finally
            {
                sql = null;
            }
        }
Ejemplo n.º 2
0
        /*
         * Constructs the LargeObject API.
         *
         * <p><b>Important Notice</b>
         * <br>This method should only be called by org.postgresql.Connection
         *
         * <p>There should only be one LargeObjectManager per Connection. The
         * org.postgresql.Connection class keeps track of the various extension API's
         * and it's advised you use those to gain access, and not going direct.
         */
        public LargeObjectManager(NpgsqlConnection conn)
        {
            // We need Fastpath to do anything
            // Now get the function oid's for the api
            //
            // This is an example of Fastpath.addFunctions();
            //
            String sql;

            if (conn.ServerVersion > new ServerVersion(7, 3, 0))
            {
                sql = "SELECT p.proname,p.oid " +
                      " FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n " +
                      " WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND (";
            }
            else
            {
                sql = "SELECT proname,oid FROM pg_proc WHERE ";
            }
            sql += " proname = 'lo_open'" +
                   " or proname = 'lo_close'" +
                   " or proname = 'lo_creat'" +
                   " or proname = 'lo_unlink'" +
                   " or proname = 'lo_lseek'" +
                   " or proname = 'lo_tell'" +
                   " or proname = 'loread'" +
                   " or proname = 'lowrite'";

            if (conn.ServerVersion > new ServerVersion(7, 3, 0))
            {
                sql += ")";
            }

            IDbCommand cmd = new NpgsqlCommand(sql);

            cmd.Connection = conn;

            this.fp = new Fastpath(conn, conn.Connector.Stream);

            IDataReader res = cmd.ExecuteReader(CommandBehavior.CloseConnection);


            if (res == null)
            {
                throw new NpgsqlException("postgresql.lo.init");
            }


            fp.AddFunctions(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs the LargeObject API.
        /// There should only be one LargeObjectManager per Connection. The
        /// org.postgresql.Connection class keeps track of the various extension API's
        /// and it's advised you use those to gain access, and not going direct.
        /// </summary>
        /// <param name="conn"></param>
        public LargeObjectManager(NpgsqlConnection conn)
        {
            // We need Fastpath to do anything
            // Now get the function oid's for the api
            //
            // This is an example of Fastpath.addFunctions();
            //
            //String sql;
            StringBuilder sql = null;
            try
            {
                sql = new StringBuilder();
                sql.Append("SELECT p.proname,p.oid ");
                sql.Append(" FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n ");
                sql.Append(" WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND (");
                sql.Append(" proname = 'lo_open'");
                sql.Append(" or proname = 'lo_close'");
                sql.Append(" or proname = 'lo_creat'");
                sql.Append(" or proname = 'lo_unlink'");
                sql.Append(" or proname = 'lo_lseek'");
                sql.Append(" or proname = 'lo_tell'");
                sql.Append(" or proname = 'loread'");
                sql.Append(" or proname = 'lowrite'");
                sql.Append(")");

                using (IDbCommand cmd = new NpgsqlCommand(sql.ToString()))
                {
                    cmd.Connection = conn;

                    this.fp = new Fastpath(conn, conn.Connector.Stream);

                    using (IDataReader res = cmd.ExecuteReader())
                    {
                        fp.AddFunctions(res);
                    }
                }
            }
            finally
            {
                sql = null;
            }
        }
Ejemplo n.º 4
0
        /*
         * Constructs the LargeObject API.
         *
         * <p><b>Important Notice</b>
         * <br>This method should only be called by org.postgresql.Connection
         *
         * <p>There should only be one LargeObjectManager per Connection. The
         * org.postgresql.Connection class keeps track of the various extension API's
         * and it's advised you use those to gain access, and not going direct.
         */
        public LargeObjectManager(NpgsqlConnection conn)
        {
            // We need Fastpath to do anything
            // Now get the function oid's for the api
            //
            // This is an example of Fastpath.addFunctions();
            //
            String sql;
            if (conn.ServerVersion > new ServerVersion(7,3,0) )
            {

                sql = "SELECT p.proname,p.oid "+
                      " FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n "+
                      " WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND (";
            }
            else
            {
                sql = "SELECT proname,oid FROM pg_proc WHERE ";
            }
            sql += " proname = 'lo_open'" +
                   " or proname = 'lo_close'" +
                   " or proname = 'lo_creat'" +
                   " or proname = 'lo_unlink'" +
                   " or proname = 'lo_lseek'" +
                   " or proname = 'lo_tell'" +
                   " or proname = 'loread'" +
                   " or proname = 'lowrite'";

            if (conn.ServerVersion > new ServerVersion(7,3,0) )
            {
                sql += ")";
            }

            IDbCommand cmd = new NpgsqlCommand(sql);
            cmd.Connection = conn;

            this.fp = new Fastpath(conn,conn.Connector.Stream);

            IDataReader res = cmd.ExecuteReader(CommandBehavior.CloseConnection);


            if (res == null)
                throw new NpgsqlException("postgresql.lo.init");


            fp.AddFunctions(res);
        }