Esempio n. 1
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();
                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;
            }
        }
Esempio n. 2
0
        private Boolean closed = false; // true when we are closed

        /// <summary>
        /// This opens a large object.
        /// If the object does not exist, then an NpgsqlException is thrown.
        /// </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);
        }