Re: How to store text files in the postgresql?

Поиск
Список
Период
Сортировка
От Johan Nel
Тема Re: How to store text files in the postgresql?
Дата
Msg-id h0g7pb$di0$1@news.eternal-september.org
обсуждение исходный текст
Ответ на How to store text files in the postgresql?  (DimitryASuplatov <genesup@gmail.com>)
Список pgsql-general
> 1/ Is it possible?
> 2/ Could you give me some quick tips on how to manage it from the start
> so that I knew what to look for in the manual?

Not sure how much you know about programming, but easiest will probably
be to have a small application.  Here is some code in the Npgsql library
documentation that shows how to do it in C#:

using System;
using System.Data;
using Npgsql;
using System.IO;
public class t
{
   public static void Main(String[] args)
   {
     NpgsqlConnection conn = new NpgsqlConnection(
       "server=localhost;user id=npgsql_tests;password=npgsql_tests");
     conn.Open();
     FileStream fs = new FileStream(args[0], FileMode.Open,
       FileAccess.Read);
     BinaryReader br = new BinaryReader(new BufferedStream(fs));
     Byte[] bytes = br.ReadBytes((Int32)fs.Length);
     Console.WriteLine(fs.Length);
     br.Close();
     fs.Close();
     NpgsqlCommand command = new NpgsqlCommand(
       "insert into tableBytea(field_bytea) values(:bytesData)", conn);
     NpgsqlParameter param = new NpgsqlParameter(
       ":bytesData", DbType.Binary);
     param.Value = bytes;
     command.Parameters.Add(param);
     command.ExecuteNonQuery();
     command = new NpgsqlCommand(
       "select field_bytea from tableBytea " +
       "where field_serial = (select max(select field_serial) from " +
       "tableBytea);", conn);
     Byte[] result = (Byte[])command.ExecuteScalar();
     fs = new FileStream(args[0] + "database", FileMode.Create,
       FileAccess.Write);
     BinaryWriter bw = new BinaryWriter(new BufferedStream(fs));
     bw.Write(result);
     bw.Flush();
     fs.Close();
     bw.Close();
     conn.Close();
   }
}

HTH,

Johan Nel
Pretoria, South Africa.

В списке pgsql-general по дате отправления:

Предыдущее
От: Grzegorz Jaśkiewicz
Дата:
Сообщение: Re: xml to table (as oppose to table to xml)
Следующее
От: Dimitri Fontaine
Дата:
Сообщение: Re: How to store text files in the postgresql?