summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-04-09 05:52:43 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-04-09 05:52:43 +0000
commit71e3c7ee84ee3cf5bf5dfc6e29e1ce469fc605b4 (patch)
tree7df3813e307d48b13baab4e1518db4a5132b9129 /sca-cpp/trunk/components
parentcf35ada83de3ec531817a35b0c4ca2ee8f95974e (diff)
Add store test using the sqldb component. Add conninfo and table properties to sqldb component.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@932259 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/components')
-rwxr-xr-xsca-cpp/trunk/components/sqldb/pgsql-start8
-rwxr-xr-xsca-cpp/trunk/components/sqldb/pgsql-stop2
-rw-r--r--sca-cpp/trunk/components/sqldb/pgsql.hpp11
-rwxr-xr-xsca-cpp/trunk/components/sqldb/server-test4
-rwxr-xr-xsca-cpp/trunk/components/sqldb/sqldb-test4
-rw-r--r--sca-cpp/trunk/components/sqldb/sqldb.composite2
-rw-r--r--sca-cpp/trunk/components/sqldb/sqldb.cpp6
7 files changed, 26 insertions, 11 deletions
diff --git a/sca-cpp/trunk/components/sqldb/pgsql-start b/sca-cpp/trunk/components/sqldb/pgsql-start
index b87313073d..f5c0f87614 100755
--- a/sca-cpp/trunk/components/sqldb/pgsql-start
+++ b/sca-cpp/trunk/components/sqldb/pgsql-start
@@ -25,13 +25,13 @@ pgsql_prefix=`cat $here/pgsql.prefix`
mkdir -p $root/sqldb
mkdir -p $root/logs
if [ ! -f $root/sqldb/postgresql.conf ]; then
- $pgsql_prefix/bin/pg_ctl init -D $root/sqldb
+ $pgsql_prefix/bin/pg_ctl init -D $root/sqldb 1>/dev/null 2>&1
createdb="true"
fi
-$pgsql_prefix/bin/pg_ctl start -D $root/sqldb -l $root/logs/postgresql
-sleep 1
+$pgsql_prefix/bin/pg_ctl start -D $root/sqldb -l $root/logs/postgresql 1>/dev/null 2>&1
+sleep 2
if [ "$createdb" = "true" ]; then
- $pgsql_prefix/bin/createdb db
+ $pgsql_prefix/bin/createdb db 1>/dev/null 2>&1
fi
diff --git a/sca-cpp/trunk/components/sqldb/pgsql-stop b/sca-cpp/trunk/components/sqldb/pgsql-stop
index f840a85e0c..d0cda096ba 100755
--- a/sca-cpp/trunk/components/sqldb/pgsql-stop
+++ b/sca-cpp/trunk/components/sqldb/pgsql-stop
@@ -24,5 +24,5 @@ root=`readlink -f $1`
pgsql_prefix=`cat $here/pgsql.prefix`
mkdir -p $root/sqldb
mkdir -p $root/logs
-$pgsql_prefix/bin/pg_ctl stop -D $root/sqldb
+$pgsql_prefix/bin/pg_ctl stop -D $root/sqldb 1>/dev/null 2>&1
diff --git a/sca-cpp/trunk/components/sqldb/pgsql.hpp b/sca-cpp/trunk/components/sqldb/pgsql.hpp
index b6b2cab331..08e8a44123 100644
--- a/sca-cpp/trunk/components/sqldb/pgsql.hpp
+++ b/sca-cpp/trunk/components/sqldb/pgsql.hpp
@@ -162,8 +162,19 @@ const failable<bool> put(const value& key, const value& val, const PGSql& pgsql)
PGresult* r = PQexecPrepared(pgsql.conn, "put", 2, params, NULL, NULL, 0);
if (PQresultStatus(r) != PGRES_COMMAND_OK)
return mkfailure<bool>(string("Could not execute put SQL statement: ") + pgfailure(r));
+ const string t = PQcmdTuples(r);
+ if (t != "0") {
+ PQclear(r);
+ debug(true, "pgsql::put::result");
+ return true;
+ }
PQclear(r);
+ PGresult* pr = PQexecPrepared(pgsql.conn, "post", 2, params, NULL, NULL, 0);
+ if (PQresultStatus(pr) != PGRES_COMMAND_OK)
+ return mkfailure<bool>(string("Could not execute post SQL statement: ") + pgfailure(pr));
+ PQclear(pr);
+
debug(true, "pgsql::put::result");
return true;
}
diff --git a/sca-cpp/trunk/components/sqldb/server-test b/sca-cpp/trunk/components/sqldb/server-test
index bcd8f266d7..784c7156c5 100755
--- a/sca-cpp/trunk/components/sqldb/server-test
+++ b/sca-cpp/trunk/components/sqldb/server-test
@@ -27,8 +27,8 @@ SCAComposite sqldb.composite
EOF
./pgsql-start tmp
-./pgsql "drop table test" 1>/dev/null 2>&1
-./pgsql "create table test(key varchar(80), value varchar(200));" 1>/dev/null 2>&1
+./pgsql "drop table test;" 1>/dev/null 2>&1
+./pgsql "create table test(key text, value text);" 1>/dev/null 2>&1
../../modules/http/httpd-start tmp
sleep 2
diff --git a/sca-cpp/trunk/components/sqldb/sqldb-test b/sca-cpp/trunk/components/sqldb/sqldb-test
index c51e51df0c..05fe413d50 100755
--- a/sca-cpp/trunk/components/sqldb/sqldb-test
+++ b/sca-cpp/trunk/components/sqldb/sqldb-test
@@ -19,8 +19,8 @@
# Setup
./pgsql-start tmp
-./pgsql "drop table test" 1>/dev/null 2>&1
-./pgsql "create table test(key varchar(80), value varchar(80));" 1>/dev/null 2>&1
+./pgsql "drop table test;" 1>/dev/null 2>&1
+./pgsql "create table test(key text, value text);" 1>/dev/null 2>&1
# Test
./pgsql-test 2>/dev/null
diff --git a/sca-cpp/trunk/components/sqldb/sqldb.composite b/sca-cpp/trunk/components/sqldb/sqldb.composite
index 39b1e54b7e..9675340b0c 100644
--- a/sca-cpp/trunk/components/sqldb/sqldb.composite
+++ b/sca-cpp/trunk/components/sqldb/sqldb.composite
@@ -24,6 +24,8 @@
<component name="sqldb">
<implementation.cpp path=".libs" library="libsqldb"/>
+ <property name="conninfo">dbname=db</property>
+ <property name="table">test</property>
<service name="sqldb">
<t:binding.http uri="sqldb"/>
</service>
diff --git a/sca-cpp/trunk/components/sqldb/sqldb.cpp b/sca-cpp/trunk/components/sqldb/sqldb.cpp
index bec4c47a2b..e84a732511 100644
--- a/sca-cpp/trunk/components/sqldb/sqldb.cpp
+++ b/sca-cpp/trunk/components/sqldb/sqldb.cpp
@@ -111,8 +111,10 @@ private:
* Start the component.
*/
const failable<value> start(unused const list<value>& params) {
- // Connect to the database
- pgsql::PGSql& pg = *(new (gc_new<pgsql::PGSql>()) pgsql::PGSql("dbname=db", "test"));
+ // Connect to the configured database and table
+ const value conninfo = ((lambda<value(list<value>)>)car(params))(list<value>());
+ const value table = ((lambda<value(list<value>)>)cadr(params))(list<value>());
+ pgsql::PGSql& pg = *(new (gc_new<pgsql::PGSql>()) pgsql::PGSql(conninfo, table));
// Return the component implementation lambda function
return value(lambda<value(const list<value>&)>(applySqldb(pg)));