This class implements the Fastpath api.
Esempio 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;
            }
        }
		private Boolean closed = false; // true when we are closed

		/*
         * This opens a large object.
         *
         * <p>If the object does not exist, then an NpgsqlException is thrown.
         *
         * @param fp FastPath API for the connection to use
         * @param oid of the Large Object to open
         * @param mode Mode of opening the large object
         * (defined in LargeObjectManager)
         * @exception NpgsqlException if a database-access error occurs.
         * @see org.postgresql.largeobject.LargeObjectManager
         */

		public LargeObject(Fastpath fp, Int32 oid, Int32 mode)
		{
			this.fp = fp;
			this.oid = oid;

			FastpathArg[] args = new FastpathArg[2];
			args[0] = new FastpathArg(oid);
			args[1] = new FastpathArg(mode);
			this.fd = fp.GetInteger("lo_open", args);
		}
Esempio n. 3
0
        private Boolean closed = false; // true when we are closed

        /// <summary>
        /// This opens a large object.
        /// </summary>
        /// <param name="fp">FastPath API for the connection to use.</param>
        /// <param name="oid">OID of the Large Object to open.</param>
        /// <param name="mode">Mode of opening the large object</param>
        public LargeObject(Fastpath fp, Int32 oid, Int32 mode)
        {
            this.fp  = fp;
            this.oid = oid;

            FastpathArg[] args = new FastpathArg[2];
            args[0] = new FastpathArg(oid);
            args[1] = new FastpathArg(mode);
            this.fd = fp.GetInteger("lo_open", args);
        }
Esempio 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);
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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);
        }