General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract a value from database - using command line ?

Syed Madar J S
Frequent Advisor

How to extract a value from database - using command line ?

Hi,
i guess it would be possible to extract a value from database - using command line or shell scripting.

Please throw some light on this as i am new to this concept.
5 REPLIES
Steven E. Protter
Exalted Contributor

Re: How to extract a value from database - using command line ?

Shalom,

It would be helpful to know what database we're talking about here.

Bottom line is most database servers come with a binary for extracting data from the database files. Now due to security concerns the raw database files may have encrypted data in them, making it impossible to extract anything from the command line but gibberish.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OldSchool
Honored Contributor

Re: How to extract a value from database - using command line ?

most databases have a command line interface, and it varies by db...

if it does, then you can use "here-docs" to extract data using a shell script. see the "man" page for whatever shell you are using. the concept is something along the lines of:

my_query_command <<-EOF
select blah from blahblah
EOF
Syed Madar J S
Frequent Advisor

Re: How to extract a value from database - using command line ?

we are trying to extract value from "Postgre SQL"

we are using a method "cldb_getAllElements"

This method is suppose to return the list of elements in the set.

But when we remove all elements, and then try using the above method - we are encountering an error - as it tries to access an empty-list.!!

### This was the main problem ####

so i thought of extracting elements from database to check if the list is empty - through command line (Unix Shell) itself.

I guessed this might be a possible solution.
Syed Madar J S
Frequent Advisor

Re: How to extract a value from database - using command line ?

/*#### this is the C++ method used to get the list ####*/

void Cldb::getAllElements(string * result, int *status) {

string sql = string("SELECT short_name ");

sql.append(" FROM node, element ");
sql.append(" WHERE element.management_node_id != node.node_id;\n");

char *answer;

mysqlResult(sql, "getAllElements", status, &answer);
if( *status == 0) {
*result = trimHeaderFromSqlOutput(answer);
} else {
*result = string("");
}
}



=================================


Any idea as how to deal with an empty-list when this method is called ?
Syed Madar J S
Frequent Advisor

Re: How to extract a value from database - using command line ?

Thanks all