Wednesday, 24 June 2009

Insert Large Amount Of Rows Into PostgreSQL

Inserting large amount of data into postgres database may take a lot of time, if you use INSERT command. Consider better COPY command, though it is not so flexible.
COPY my_table_name(int_column, string_column, bytea_column) from stdin;
1    THISisSTRING    \\001\\017\\044
2    THISisSTRING2   \\001\\017\\062
3    THISisSTRING3   \\001\\017\\102

The default delimiter is tab (\t).

To acquire the right format in 1 particular case, you can fill database with some values using INSERT command and dump database with pg_dump. The resulting file will contain the right COPY syntax.

Monday, 22 June 2009

Ajax With InnerHTML()

InnerHTML is not a standard, but it is more useful comparing to working with DOM with such functions as createElement and/or appendChild. But there is a problem with it: if you need further to handle the new added data (to refer new elements, to change/add their attributes), innerHTML is not good at all, as innerHTML simply visually adds new elements, but it does not really insert them in the DOM structure of the document. Attempting to do a document.getElementById() on a tag inside of code that was added using innerHTML just doesn't work. At least it didn't work for me in Firefox 3.

The folowing code can be accepted as the workaround.

var newDiv = document.createElement("div");//create new div
newDiv.innerHTML = xhr.responseText;//add response into new div
var container = document.getElementById("container");//find place where the response should be placed to
container.parentNode.insertBefore(newDiv, container);//add new div before the container
newDiv.parentNode.removeChild(container);//remove container

This way we get the same resulting document, but we can further work with DOM.

Friday, 12 June 2009

Master Degree Acquired

Yes, at last. Now I am the Master of the Information Technology :) Sounds good!

Wednesday, 10 June 2009

Microsoft Excel 2007 Problems

It is a must read, if you want to know what problems you may encounter, when exporting to excel 2007: "Microsoft Office XML formats ? Defective by design"

Sunday, 7 June 2009

Array To String

Oh, how I hate String.join(string, string[]) in mscorlib. And it is because of string[] argument. Why couldn't they make it accept array of objects and, before joining, cast every object with ToString() method?

Had to make it myself:

public string ListJoin<T>(string separator, T[] objs)//C# v3
  return string.Join(separator, Array.ConvertAll(objs, item => item.ToString()));

public string ListJoin<T>(string separator, T[] objs)//C# v2
  return string.Join(separator, Array.ConvertAll<T,string>(value, new Converter<T,string>(delegate(T i){return i.ToString();})));