Hi,

Today i try explain about returning table’s (dataset) using function’s in PostgreSQL.
First you need create table object for using in return the function.

create type table_temp as (
	id integer,
	name varchar(50),
	age smallint
);

This command create the type.

Now i demonstrate one very simple function using object in return.:

CREATE OR REPLACE FUNCTION getTemp() RETURNS SETOF table_temp AS
$BODY$
DECLARE
	varReturn table_temp;
BEGIN
	varReturn.id := 1;
	varReturn.name := 'Person 01';
	varReturn.age := 29;
	return next varReturn;

	varReturn.id := 2;
	varReturn.name := 'Person 02';
	varReturn.age := 19;
	return next varReturn;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE

This SQL create simple function than return two row’s.

Ok, for testing use this SQL:

select * from getTemp()

You receive two row’s, some tables (dataset).

Notes:

  • In RETURNS the FUNCTION ever use “RETURNS SETOF + type”, “SETOF” setting the return of the function for using more row’s. In my case “RETURNS SETOF table_temp”
  • Declare one variable for use for setting each row. In my example “variable varReturn”.
  • The command “return next + variable”, fetch row using parameters setted in variable of type. In my case “return next varReturn”.
  • Finally, when you use in your SQL’s, use like a table, not like a column. Use “SELECT * FROM YOUR_FUNCTION()”, e don’t “SELECT YOUR_FUNCTION()”.

See you later.

Changing Root Password.

August 19th, 2009

If you lose password root of your server, and you use lilo or grub boot, is very simple for changing.

In grub boot screen edit line we have “kernel”, in the end of this line, input this:

init=/bin/bash

In Lilo just input this in boot:

linux init=/bin/bash

Start linux and waiting for bash initialize, after go mounting the device.

mount -orw,remount /

Ok, you now have the device mounted. Now change the password.

passwd root

See you later.

Hi,

If you receive this message, is very simple.
In example below, occurs this message:

CREATE OR REPLACE FUNCTION myfunc() RETURNS integer AS '
	require_once("/opt/lampp/htdocs/file.php");
	...
' LANGUAGE 'plphp'; 

For solve just change the ‘plphp’ for ‘plphpu’.

CREATE OR REPLACE FUNCTION myfunc() RETURNS integer AS '
	require_once("/opt/lampp/htdocs/file.php");
	...
' LANGUAGE 'plphpu'; 

Work’s….

Bye.

Hi, now i write about my new experience in last week.
In PostgreSQL sometime you need create function’s or stored procedure, but plPgSQL is little difficulty and sometimes need learn.
In my company working with PHP, the programmers working with me developing in PHP, then plPHP is a very simple solution, because don’t need learning.

Ok, go the solution.

You need first:
– Ubuntu.
– PostgreSQL 8.3, installed for repository.
– plPHP 1.3.5.

Now you need of the pakage server-dev:

sudo apt-get install postgresql-server-dev-8.3

And the pg_config is necessary, to install then:

sudo apt-get install libpq-dev

Now, go to compiling other php. For not make a trouble in Apache e php existed.
Extract source, and open the directory and:

sudo ./configure --prefix=/usr/local/plphp --enable-embed
sudo make
sudo make install

Compiling plPHP. Open the directory with you extract the source’s and:

sudo ./configure --with-php=/usr/local/plphp
sudo make
sudo make install

Linking the php library in lib directory of PostgreSQL:

sudo ln -sf /usr/local/plphp/lib/libphp5.so $(pg_config --libdir)

Now you need run two SQL commands, using master user (postgres):

INSERT INTO pg_pltemplate VALUES
('plphp', 't','t','plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);

And

INSERT INTO pg_pltemplate VALUES
('plphpu', 'f', 'f','plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);

OK, now using your user, database and schema, you install the language:

create language plphp;

And if you need access files you need create the this language:

create language plphpu;

Ok, that’s all.

Testing using:

CREATE FUNCTION helloworld() RETURNS string AS $$
	$res = "Hello World";
	return $res;
$$ STRICT LANGUAGE 'plphp';

Run the function:

select helloworld()

Bye.

In javascript you can use Object for parameter function’s.
Sample:

function test({
	param1:value,
	param2:value,
	param3: [1,2,3,4]
});

If you need list methods or variables of object you need jQuery.
In another moment i explain better about jQuery.

This function list:

obj = {param1:value,param2:value};
jQuery.each(obj, function(name, value) {
	alert(name + " = " + value);
});

Simple… bye

In javascript when you use replace in string’s the function only replace the first math located.
Now i show how you use the replace in javascript.

Only replace:

sString = "hemmo wormd !!";
sString = sString.replace("m", "l");
alert(sString);

This code showing “helmo wormd !!”.

If you need of replace all words, do it:

sString = "hemmo wormd !!";
sString = sString.replace(/m/g,"l");
alert(sString);

Now showing “hello world !!”.

Case you created the replaceAll prototype, use this sample:

String.prototype.replaceAll = function(sSearch, sReplace, bInsensitive){
	if (bInsensitive)
		return this.replace(new RegExp(sSearch,"gi"), sReplace);
	else
		return this.replace(new RegExp(sSearch,"g"), sReplace);
}

Now is a very simple:

sString = "hemmo wormd !!";
sString = sString.replaceAll("m","l"); // Case Sensitive
sString = sString.replaceAll("m","l", true); // Case Insensitive

Bye.

Hi, today i needed install Firebird 2.1 in my machine.
First, i trying installing using Synaptic, but not work.

Now, you can install using this commands:

Classic Server:

sudo apt-get install firebird2.1-classic

Super Server:

sudo apt-get install firebird2.1-super

After install, you need configure SYSDBA password:

Classic Server:

sudo dpkg-reconfigure firebird2.1-classic

Super Server:

sudo dpkg-reconfigure firebird2.1-super

See you later.

If you receive this message in your console:
“relation does not exist postgres”

Probably you created other schema, and don’t used public schema.
For default Postgres set user search path only for public schema. You has change the search path.

In PostgreSQL 8.0 or better use:

ALTER ROLE your_user SET search_path=your_schema;

Or in other versions:

ALTER USER your_user SET search_path TO your_schema;

Ok, disconnect your connection, and connect again.
Bye.

Hi,

Sometimes if you install Oracle XE 10g and you not access remote application (APEX) in your browser.
The address http://yourhost:8080/apex don’t access.

For solve this problem execute this command in SQL Plus:

EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE)

This command allow remote access in Oracle XE 10g.

Bye.

Today i explain how you sign Java Applications.
Some times you need develop application that need write or read file in other computer’s through applet.
And you receive in your java console this message:

java.security.AccessControlException: access denied (java.io.FilePermission …

For you make this you need sign your applet.

  • First you need the certificate “Code Signed”. You need buy him.

Now you need list the key’s contents in your certificate:

keytool -list -storetype pkcs12 -keystore /path/to/your/certificate.p12

For signing your applet make this command:

jarsigner -storetype pkcs12 -keystore /path/to/your/certificate.p12 yourJar.jar "Alias"

Being “Alias” your alias returned in command keytool -list.

Now, if you need, this command verify if you applet is signed:

jarsigner -verify -verbose -certs yourjar.jar

Ok, your Applet is signed, but some times this isn’t enough. Java console continued displayed the error message.

Some cases in if you call the void’s or function’s of applet by Javascript the permission error continued.

For solving, use in your code that dispatch the exception this code:

AccessController.doPrivileged(new PrivilegedAction() {
	public Object run() {
		// YOUR CODE HERE
	return null;
});

Sample how to use:

public void PrintReport() {
	AccessController.doPrivileged(new PrivilegedAction() {
		public Object run() {
			FileOutputStream fos = null;
			PrintStream ps = null;
			try{
				fos = new FileOutputStream("LPT1:");
				ps = new PrintStream(fos);
				ps.println("print line");
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			ps.close();
			return null;
		}
	});
}

Is this, i hope help you.
Bye.