Example #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;
            }
        }
Example #2
0
        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);
        }
Example #3
0
		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);
		}
Example #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;
			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;
			}
		}