[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash server/array.cpp ChangeLog extensions/dej...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash server/array.cpp ChangeLog extensions/dej... |
Date: |
Fri, 15 Dec 2006 20:51:43 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 06/12/15 20:51:43
Modified files:
server : array.cpp
. : ChangeLog
extensions/dejagnu: Makefile.am dejagnu.cpp dejagnu.h
extensions/mysql: mysql_db.cpp mysql_db.h
Added files:
extensions/mysql: Makefile.am test.as test.sql
Log message:
* server/array.cpp: Add the size operator, which wasn't being
added
as a member.
* extensions/mysql/Makefile.am:
* extensions/mysql/mysql_table.h: Remove.
* extensions/mysql/mysql_db.cpp, mysql_db.h: Tottally
reqritten. Work as a Gnash extension. Add methods for MySQL API,
as well as a generic getData() method for simple queries.
* extensions/mysql/test.as: Test the MySQL extension.
* extensions/mysql/test.sql: MySQL schema for test case.
* extensions/dejagnu/Makefile.am: Use libdir instead of
prefix. Include from asobjs too, and also link in
libgnashvm. Don't build Sharedtest.
* extensions/dejagnu/dejagnu.cpp: Setup the members
correctly. Don't attach twice for this class.
* extensions/dejagnu/test.as: Use pass and fail.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/array.cpp?cvsroot=gnash&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1944&r2=1.1945
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/dejagnu/Makefile.am?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/dejagnu/dejagnu.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/dejagnu/dejagnu.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/mysql/mysql_db.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/mysql/mysql_db.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/mysql/Makefile.am?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/mysql/test.as?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/mysql/test.sql?cvsroot=gnash&rev=1.1
Patches:
Index: server/array.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/array.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- server/array.cpp 21 Nov 2006 10:53:08 -0000 1.44
+++ server/array.cpp 15 Dec 2006 20:51:43 -0000 1.45
@@ -603,6 +603,16 @@
fn.result->set_string(ret.c_str());
}
+static void
+array_size(const fn_call& fn)
+{
+ assert(dynamic_cast<as_array_object*>(fn.this_ptr));
+ as_array_object* array = \
+ static_cast<as_array_object*>(fn.this_ptr);
+
+ fn.result->set_int(array->size());
+}
+
// Callback to convert array to a string
static void
array_to_string(const fn_call& fn)
@@ -786,6 +796,7 @@
proto.set_member("shift", &array_shift);
proto.set_member("splice", &array_splice);
proto.set_member("sort", &array_sort);
+ proto.set_member("size", &array_size);
proto.set_member("sortOn", &array_sortOn);
proto.set_member("reverse", &array_reverse);
proto.set_member("toString", &array_to_string);
@@ -825,7 +836,6 @@
// We replicate interface to the Array class itself
attachArrayInterface(*ar);
-
}
// Register _global.Array
@@ -833,4 +843,11 @@
}
-}
+} // end of gnash namespace
+
+
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
+
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1944
retrieving revision 1.1945
diff -u -b -r1.1944 -r1.1945
--- ChangeLog 15 Dec 2006 16:48:57 -0000 1.1944
+++ ChangeLog 15 Dec 2006 20:51:43 -0000 1.1945
@@ -1,3 +1,21 @@
+2006-12-15 Rob Savoye <address@hidden>
+
+ * server/array.cpp: Add the size operator, which wasn't being added
+ as a member.
+ * extensions/mysql/Makefile.am:
+ * extensions/mysql/mysql_table.h: Remove.
+ * extensions/mysql/mysql_db.cpp, mysql_db.h: Tottally
+ reqritten. Work as a Gnash extension. Add methods for MySQL API,
+ as well as a generic getData() method for simple queries.
+ * extensions/mysql/test.as: Test the MySQL extension.
+ * extensions/mysql/test.sql: MySQL schema for test case.
+ * extensions/dejagnu/Makefile.am: Use libdir instead of
+ prefix. Include from asobjs too, and also link in
+ libgnashvm. Don't build Sharedtest.
+ * extensions/dejagnu/dejagnu.cpp: Setup the members
+ correctly. Don't attach twice for this class.
+ * extensions/dejagnu/test.as: Use pass and fail.
+
2006-12-14 Sandro Santilli <address@hidden>
* testsuite/misc-ming.all/Makefile.am:
Index: extensions/dejagnu/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/extensions/dejagnu/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- extensions/dejagnu/Makefile.am 24 Nov 2006 19:17:37 -0000 1.2
+++ extensions/dejagnu/Makefile.am 15 Dec 2006 20:51:43 -0000 1.3
@@ -18,10 +18,7 @@
AUTOMAKE_OPTIONS =
# this is where Gnash plugins get installed
-pluginsdir = $(prefix)/lib/gnash/plugins
-
-# __USLC__ makes MySQL++ use the std namespace
-AM_CXXFLAGS = -g -D__USLC__
+pluginsdir = $(libdir)/gnash/plugins
plugins_LTLIBRARIES = dejagnu.la
@@ -29,28 +26,26 @@
-I$(top_srcdir)/libbase \
-I$(top_srcdir)/server \
-I$(top_srcdir)/server/vm \
+ -I$(top_srcdir)/asobjs \
$(INCLTDL)
AM_LDFLAGS = \
+ $(top_builddir)/libbase/libgnashbase.la \
$(top_builddir)/backend/libgnashbackend.la \
+ $(top_builddir)/server/libgnashserver.la \
$(top_builddir)/server/vm/libgnashvm.la \
- $(LIBADD_DL) \
- $(LIBLTDL) \
$(PTHREAD_LIBS) \
$(NULL)
dejagnu_la_SOURCES = dejagnu.cpp dejagnu.h
-dejagnu_la_LDFLAGS = -module -avoid-version # -no-undefined
+dejagnu_la_LDFLAGS = -module -avoid-version
dejagnu_la_LIBDADD = $(LIBADD_DL) $(LIBLTDL) $(AM_LDFLAGS)
check_PROGRAMS = SharedTest
CLEANFILES = \
gnash-dbg.log
-SharedTest_SOURCES = SharedTest.cpp
-SharedTest_CPPFLAGS = '-DINPUT="$(srcdir)/SharedTest.cpp"'
-SharedTest_LDFLAGS = -export-dynamic
-
install-pluginsLTLIBRARIES: $(plugins_LTLIBRARIES)
test -d "$(DESTDIR)$(pluginsdir)" || $(mkinstalldirs)
"$(DESTDIR)$(pluginsdir)"
$(LIBTOOL) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG)
$(plugins_LTLIBRARIES) "$(DESTDIR)$(pluginsdir)/$(plugins_LTLIBRARIES)"
+ $(RM) $(DESTDIR)$(pluginsdir)/*.a
\ No newline at end of file
Index: extensions/dejagnu/dejagnu.cpp
===================================================================
RCS file: /sources/gnash/gnash/extensions/dejagnu/dejagnu.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- extensions/dejagnu/dejagnu.cpp 24 Nov 2006 19:17:37 -0000 1.2
+++ extensions/dejagnu/dejagnu.cpp 15 Dec 2006 20:51:43 -0000 1.3
@@ -23,8 +23,6 @@
#include <string>
#include "log.h"
#include "dejagnu.h"
-#include "sharedlib.h"
-#include "extension.h"
#include "fn_call.h"
#include "as_object.h"
#include "builtin_function.h" // need builtin_function
@@ -47,23 +45,22 @@
};
static void
-attachDejaGnuInterface(as_object *obj)
+attachInterface(as_object *obj)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
- obj->set_member("pass", dejagnu_pass);
- obj->set_member("fail", dejagnu_fail);
- obj->set_member("totals", dejagnu_totals);
+ obj->set_member("pass", &dejagnu_pass);
+ obj->set_member("fail", &dejagnu_fail);
+ obj->set_member("totals", &dejagnu_totals);
}
static as_object*
-getDejaGnuInterface()
+getInterface()
{
- GNASH_REPORT_FUNCTION;
- static boost::intrusive_ptr<as_object> o=NULL;
+// GNASH_REPORT_FUNCTION;
+ static boost::intrusive_ptr<as_object> o;
if (o == NULL) {
o = new as_object();
- attachDejaGnuInterface(o.get());
}
return o.get();
}
@@ -71,28 +68,30 @@
static void
dejagnu_ctor(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
dejagnu_as_object* obj = new dejagnu_as_object();
+// attachInterface(obj);
fn.result->set_as_object(obj); // will keep alive
+ printf ("Hello World from %s !!!\n", __PRETTY_FUNCTION__);
}
DejaGnu::DejaGnu()
: passed(0), failed(0), xpassed(0), xfailed(0)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
}
DejaGnu::~DejaGnu()
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
}
const char *
DejaGnu::pass (const char *msg)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
passed++;
dbglogfile << "PASSED: " << msg << endl;
@@ -101,7 +100,7 @@
const char *
DejaGnu::fail (const char *msg)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
failed++;
dbglogfile << "FAILED: " << msg << endl;
@@ -110,7 +109,7 @@
void
dejagnu_pass(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
dejagnu_as_object *ptr = (dejagnu_as_object*)fn.this_ptr;
assert(ptr);
@@ -123,7 +122,7 @@
void
dejagnu_fail(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
dejagnu_as_object *ptr = (dejagnu_as_object*)fn.this_ptr;
assert(ptr);
@@ -136,7 +135,7 @@
void
dejagnu_totals(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
dejagnu_as_object *ptr = (dejagnu_as_object*)fn.this_ptr;
assert(ptr);
@@ -144,21 +143,27 @@
fn.result->set_bool(true);
}
+
+std::auto_ptr<as_object>
+init_dejagnu_instance()
+{
+ return std::auto_ptr<as_object>(new dejagnu_as_object());
+}
+
extern "C" {
void
dejagnu_class_init(as_object &obj)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
// This is going to be the global "class"/"function"
- static boost::intrusive_ptr<builtin_function> cl=NULL;
+ static boost::intrusive_ptr<builtin_function> cl;
if (cl == NULL) {
- cl = new builtin_function(&dejagnu_ctor, getDejaGnuInterface());
- // replicate all interface to class, to be able to access
- // all methods as static functions
- attachDejaGnuInterface(cl.get());
+ cl = new builtin_function(&dejagnu_ctor, getInterface());
+// // replicate all interface to class, to be able to access
+// // all methods as static functions
+ attachInterface(cl.get());
}
- printf ("Hello World from %s !!!\n", __PRETTY_FUNCTION__);
obj.set_member("DejaGnu", cl.get());
}
} // end of extern C
Index: extensions/dejagnu/dejagnu.h
===================================================================
RCS file: /sources/gnash/gnash/extensions/dejagnu/dejagnu.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- extensions/dejagnu/dejagnu.h 24 Nov 2006 19:17:37 -0000 1.2
+++ extensions/dejagnu/dejagnu.h 15 Dec 2006 20:51:43 -0000 1.3
@@ -23,14 +23,10 @@
#include <memory> // for auto_ptr
#include "as_object.h"
-#include "sharedlib.h"
-#include "extension.h"
namespace gnash
{
-class as_object;
-
class DejaGnu {
public:
DejaGnu();
@@ -49,12 +45,11 @@
extern "C" {
void dejagnu_class_init(as_object &obj);
+ /// Return an instance
}
-/// Return an instance
std::auto_ptr<as_object> init_dejagnu_instance();
-
} // end of gnash namespace
// __DEJAGNU_PLUGIN_H__
Index: extensions/mysql/mysql_db.cpp
===================================================================
RCS file: /sources/gnash/gnash/extensions/mysql/mysql_db.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- extensions/mysql/mysql_db.cpp 29 Oct 2006 18:34:17 -0000 1.3
+++ extensions/mysql/mysql_db.cpp 15 Dec 2006 20:51:43 -0000 1.4
@@ -14,189 +14,419 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
-
#include <cstdarg>
+#include <mysql/errmsg.h>
+#include <mysql/mysql.h>
+#include <iostream>
+#include <vector>
+
+#include "log.h"
+#include "array.h"
#include "as_value.h"
#include "fn_call.h"
#include "mysql_db.h"
+#include "builtin_function.h" // need builtin_function
-#ifdef _WIN32
-# define snprintf _snprintf
-#endif
+using namespace std;
-namespace mysqldb
+namespace gnash
{
- void connect_method(const fn_call& fn)
- {
- assert(fn.this_ptr); assert(fn.env);
- db* mydb = (db*) (as_object*) fn.this_ptr;
+void mysql_connect(const fn_call& fn);
+void mysql_qetData(const fn_call& fn);
+void mysql_disconnect(const fn_call& fn);
+
+void mysql_query(const fn_call& fn);
+void mysql_row(const fn_call& fn);
+void mysql_fields(const fn_call& fn);
+void mysql_fetch(const fn_call& fn);
+void mysql_store(const fn_call& fn);
+void mysql_free(const fn_call& fn);
- if (fn.nargs < 4)
- {
- mydb->set_err("'connect' needs 4 arguments\n");
- fn.result->set_bool(false);
- return;
- }
+LogFile& dbglogfile = LogFile::getDefaultInstance();
- fn.result->set_bool(mydb->connect(fn.arg(0).to_string(),
fn.arg(1).to_string(), fn.arg(2).to_string(), fn.arg(3).to_string()));
- }
+class mysql_as_object : public as_object
+{
+public:
+ MySQL obj;
+};
- void run_method(const fn_call& fn)
- {
- assert(fn.this_ptr); assert(fn.env);
- db* mydb = (db*) (as_object*) fn.this_ptr;
+static void
+attachInterface(as_object *obj)
+{
+// GNASH_REPORT_FUNCTION;
- if (fn.nargs < 1)
- {
- mydb->set_err("'run' needs one argument");
- fn.result->set_int(-1);
- return;
- }
+ obj->set_member("connect", &mysql_connect);
+ obj->set_member("qetData", &mysql_qetData);
+ obj->set_member("disconnect", &mysql_disconnect);
+ obj->set_member("query", &mysql_query);
+ obj->set_member("fetch_row", &mysql_fetch);
+ obj->set_member("num_fields", &mysql_fields);
+ obj->set_member("free_result", &mysql_free);
+ obj->set_member("store_results", &mysql_store);
+}
- fn.result->set_int(mydb->run(fn.arg(0).to_tu_string()));
+static as_object*
+getInterface()
+{
+// GNASH_REPORT_FUNCTION;
+
+ static boost::intrusive_ptr<as_object> o;
+ if (o == NULL) {
+ o = new as_object();
}
+ return o.get();
+}
- void open_method(const fn_call& fn)
- {
- assert(fn.this_ptr); assert(fn.env);
- db* mydb = (db*) (as_object*) fn.this_ptr;
+static void
+mysql_ctor(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
- if (fn.nargs < 1)
- {
- mydb->set_err("'open' needs one argument");
- fn.result->set_null();
- return;
- }
+ mysql_as_object* obj = new mysql_as_object();
- as_object* tbl = mydb->open(fn.arg(0).to_string());
- if (tbl == NULL)
- {
- fn.result->set_null();
- return;
- }
+ attachInterface(obj);
+ fn.result->set_as_object(obj); // will keep alive
+}
- fn.result->set_as_object(tbl);
- }
- void constructor(const fn_call& fn)
- {
- *fn.result = new db();
- }
+MySQL::MySQL(): _db(NULL), _result(NULL), _row(NULL)
+{
+// GNASH_REPORT_FUNCTION;
+}
- db::db(): m_db(NULL)
- {
- as_object::set_member("connect", &connect_method);
- as_object::set_member("run", &run_method);
- as_object::set_member("open", &open_method);
+MySQL::~MySQL()
+{
+// GNASH_REPORT_FUNCTION;
+ disconnect();
+}
+
+int
+MySQL::num_fields()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_result) {
+ return num_fields(_result);
}
+ return -1;
+}
- db::~db()
- {
- disconnect();
+int
+MySQL::num_fields(MYSQL_RES *result)
+{
+// GNASH_REPORT_FUNCTION;
+ return mysql_num_fields(result);
+}
+
+MYSQL_ROW
+MySQL::fetch_row()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_result) {
+ return fetch_row(_result);
}
+ return NULL;
+}
- void db::disconnect()
- {
- if (m_db != NULL)
- {
- mysql_close(m_db);
- m_db = NULL;
+MYSQL_ROW
+MySQL::fetch_row(MYSQL_RES *result)
+{
+// GNASH_REPORT_FUNCTION;
+ return mysql_fetch_row(result);
+}
+
+void
+MySQL::free_result()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_result) {
+ free_result(_result);
}
+}
+
+void
+MySQL::free_result(MYSQL_RES *result)
+{
+// GNASH_REPORT_FUNCTION;
+ mysql_free_result(result);
+}
+
+MYSQL_RES *
+MySQL::store_result()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_db) {
+ return store_result(_db);
}
+ return NULL;
+}
+
+MYSQL_RES *
+MySQL::store_result(MYSQL *db)
+{
+// GNASH_REPORT_FUNCTION;
+ _result = mysql_store_result(db);
+ return _result;
+}
+
+bool
+MySQL::connect(const char* host, const char* dbname, const char* user, const
char* passwd)
+{
+// GNASH_REPORT_FUNCTION;
- bool db::connect(const char* host, const char* dbname, const char*
user, const char* pwd)
- {
// Closes a previously opened connection &
// also deallocates the connection handle
disconnect();
- m_db = mysql_init(NULL);
-
- if ( m_db == NULL )
- {
- set_err("no memory");
+ if ((_db = mysql_init(NULL)) == NULL ) {
+ log_error("Couldn't initialize Database!");
return false;
}
- if (mysql_real_connect(m_db, host, user, pwd, dbname, 0,
NULL, CLIENT_MULTI_STATEMENTS) == NULL)
- {
- set_err("%s", mysql_error(m_db));
+ if (mysql_real_connect(_db, host, user, passwd, dbname, 0, NULL, 0) ==
NULL) {
+ log_error("Couldn't connect to Database!");
return false;
}
- set_err("");
return true;
- }
+}
- int db::run(const tu_string& sql)
- {
- if (m_db == NULL)
- {
- set_err("missing connection");
+bool
+MySQL::guery(const char *sql)
+{
+// GNASH_REPORT_FUNCTION;
+ if (_db) {
+ return guery(_db, sql);
+ }
return -1;
+}
+
+bool
+MySQL::guery(MYSQL *db, const char *sql)
+{
+// GNASH_REPORT_FUNCTION;
+ int res = mysql_real_query(db, sql, strlen(sql));
+ switch (res) {
+ case CR_SERVER_LOST:
+ case CR_COMMANDS_OUT_OF_SYNC:
+ case CR_SERVER_GONE_ERROR:
+ dbglogfile << "MySQL connection error: " << mysql_error(_db) << endl;
+ // Try to reconnect to the database
+// closeDB();
+// openDB();
+ break;
+ case -1:
+ case CR_UNKNOWN_ERROR:
+ dbglogfile << "MySQL error on query for:\n\t " <<
+ mysql_error(_db) << endl;
+ dbglogfile << "Query was: " << sql << endl;
+ return false;
+ break;
+ default:
+ return true;
}
+}
- if (mysql_query(m_db, sql))
- {
- set_err("%s", mysql_error(m_db));
- return -1;
+int
+MySQL::getData(const char *sql, query_t &qresult)
+{
+// GNASH_REPORT_FUNCTION;
+
+ bool qstatus = false;
+ int res = mysql_real_query(_db, sql, strlen(sql));
+ switch (res) {
+ case CR_SERVER_LOST:
+ case CR_COMMANDS_OUT_OF_SYNC:
+ case CR_SERVER_GONE_ERROR:
+ dbglogfile << "MySQL connection error: " << mysql_error(_db) << endl;
+ // Try to reconnect to the database
+// closeDB();
+// openDB();
+ break;
+ case -1:
+ case CR_UNKNOWN_ERROR:
+ dbglogfile << "MySQL error on query for:\n\t " <<
+ mysql_error(_db) << endl;
+ dbglogfile << "Query was: " << sql << endl;
+// return false;
+ break;
+// default:
+// return true;
+ }
+
+ _result = mysql_store_result(_db);
+// int nrows = mysql_num_rows(result);
+
+#if 0
+ for (size_t i=0; i<mysql_num_fields(_result); i++) {
+ MYSQL_FIELD *fields = mysql_fetch_fields(_result);
+ log_msg("Field name is: %s: ", fields->name);
}
+#endif
+
+ while((_row = mysql_fetch_row(_result))) {
+ vector<const char *> row_vec;
+ for (size_t i=0; i<mysql_num_fields(_result); i++) {
+// log_msg("Column[%d] is: \"%s\"", i, row[i]);
+ row_vec.push_back(_row[i]);
+ }
+ qresult.push_back(row_vec);
+ qstatus = true;
+ }
+
+ mysql_free_result(_result);
+ return(qstatus);
+}
- set_err("");
- return mysql_affected_rows(m_db);
+bool
+MySQL::disconnect()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_db != NULL) {
+ mysql_close(_db);
+ _db = NULL;
}
+ return true;
+}
- table* db::open(const tu_string& sql)
- {
- if (m_db == NULL)
- {
- set_err("missing connection");
- return NULL;
+
+// Entry points for ActionScript methods
+void
+mysql_connect(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+
+ if (fn.nargs == 4) {
+ const char *host =
fn.env->bottom(fn.first_arg_bottom_index).to_string();
+ const char *db =
fn.env->bottom(fn.first_arg_bottom_index-1).to_string();
+ const char *user =
fn.env->bottom(fn.first_arg_bottom_index-2).to_string();
+ const char *passwd =
fn.env->bottom(fn.first_arg_bottom_index-3).to_string();
+ fn.result->set_bool(ptr->obj.connect(host, db, user, passwd));
+ } else {
+ fn.result->set_bool(false);
}
+}
- if (mysql_query(m_db, sql.c_str()))
- {
- set_err("%s", mysql_error(m_db));
- return NULL;
+void
+mysql_qetData(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+
+ if (fn.nargs > 0) {
+ const char *sql = fn.env->bottom(fn.first_arg_bottom_index).to_string();
+ as_array_object *arr = (as_array_object
*)fn.env->bottom(fn.first_arg_bottom_index-1).to_object();
+// std::vector< std::vector<const char *> >
+ MySQL::query_t qresult;
+ fn.result->set_bool(ptr->obj.getData(sql, qresult));
+ for (size_t i=0; i<qresult.size(); i++) {
+ vector<const char *> row;
+ row = qresult[i];
+ for (size_t j=0; j< row.size(); j++) {
+// cerr << "ARR: " << i << ":" << j << " " << row[j] << endl;
+ as_value entry = row[j];
+ arr->push(entry);
+ }
+ }
+ fn.result->set_bool(true);
+// } else {
+// fn.result->set_bool(false);
}
+}
- // query succeeded, process any data returned by it
- MYSQL_RES* result = mysql_store_result(m_db);
- if (result)
- {
- table* tbl = new table(result);
- mysql_free_result(result);
- set_err("");
- return tbl;
+void
+mysql_free(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+ ptr->obj.free_result();
+ fn.result->set_bool(true);
+}
+
+void
+mysql_fields(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+ fn.result->set_int(ptr->obj.num_fields());
+}
+
+void
+mysql_fetch(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+ if (fn.nargs > 0) {
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+ MYSQL_ROW res = ptr->obj.fetch_row();
+ as_value aaa = *res;
+ as_array_object *arr = new as_array_object;
+ arr->push(aaa);
+ fn.result->set_as_object(arr);
}
+}
- set_err("query does not return data");
- return NULL;
+void
+mysql_store(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+ fn.result->set_bool(ptr->obj.store_result());
+}
+
+void
+mysql_query(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ if (fn.nargs > 0) {
+ const char *sql = fn.env->bottom(fn.first_arg_bottom_index).to_string();
+ assert(ptr);
+ fn.result->set_int(ptr->obj.guery(sql));
}
+}
-// bool db::get_member(const tu_stringi& name, as_value* val)
-// {
-// return as_object::get_member(name, val);
-// }
-
-// void db::set_member(const tu_stringi& name, const as_value& val)
-// {
-// as_object::set_member(name,val);
-// }
+void
+mysql_disconnect(const fn_call& fn)
+{
+// GNASH_REPORT_FUNCTION;
- void db::set_err(const char *fmt, ...)
- {
- char msg[BUFSIZE];
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(msg, BUFSIZE, fmt, ap);
- va_end(ap);
+ mysql_as_object *ptr = (mysql_as_object*)fn.this_ptr;
+ assert(ptr);
+ fn.result->set_bool(ptr->obj.disconnect());
+}
- as_object::set_member("err", msg);
+extern "C" {
+ void
+ mysql_class_init(as_object &obj)
+ {
+// GNASH_REPORT_FUNCTION;
+ // This is going to be the global "class"/"function"
+ static boost::intrusive_ptr<builtin_function> cl;
+ if (cl == NULL) {
+ cl = new builtin_function(&mysql_ctor, getInterface());
+// // replicate all interface to class, to be able to access
+// // all methods as static functions
+// attachInterface(cl.get());
}
+ obj.set_member("MySQL", cl.get());
+ }
+
+} // end of extern C
+
+} // end of gnash namespace
-} // end of namespace mysqldb
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
Index: extensions/mysql/mysql_db.h
===================================================================
RCS file: /sources/gnash/gnash/extensions/mysql/mysql_db.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- extensions/mysql/mysql_db.h 29 Oct 2006 18:34:17 -0000 1.2
+++ extensions/mysql/mysql_db.h 15 Dec 2006 20:51:43 -0000 1.3
@@ -14,50 +14,66 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
+#ifndef __MYSQL_DB_H__
+#define __MYSQL_DB_H__
-#ifndef DB_H
-#define DB_H
-
-#include <mysql.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string>
+#include <vector>
+#include <mysql/errmsg.h>
+#include <mysql/mysql.h>
#include "as_value.h"
#include "as_object.h"
-#include "mysql_table.h"
-
+#include "extension.h"
-namespace mysqldb
+namespace gnash
{
- using namespace gnash;
-
-# define BUFSIZE 512
-
- void constructor(const fn_call& fn);
-
- class db: public as_object
- {
- public:
-
- db();
- ~db();
-// virtual bool get_member(const tu_stringi& name, as_value*
val);
-// virtual void set_member(const tu_stringi& name, const
as_value& val);
-
- void set_err(const char *fmt, ...);
-
- bool connect(const char* host, const char* dbname,
const char* user, const char* pwd);
- table* open(const tu_string& sql);
- int run(const tu_string& sql);
+class MySQL
+{
+public:
+ typedef std::vector< std::vector<const char *> > query_t;
+ MySQL();
+ ~MySQL();
+ bool connect(const char *host, const char *dbname, const char *user, const
char *passwd);
+ int getData(const char *sql, query_t &result);
+ bool disconnect();
+
+ // These are wrappers for the regular MySQL API
+ bool guery(MYSQL *db, const char *sql);
+ bool guery(const char *sql);
+ int num_fields();
+ int num_fields(MYSQL_RES *result);
+ MYSQL_ROW fetch_row();
+ MYSQL_ROW fetch_row(MYSQL_RES *result);
+ void free_result();
+ void free_result(MYSQL_RES *result);
+ MYSQL_RES *store_result();
+ MYSQL_RES *store_result(MYSQL *db);
+private:
+ MYSQL *_db;
+ MYSQL_RES *_result;
+ MYSQL_ROW _row;
+};
- private:
+extern "C" {
+ void mysql_class_init(as_object &obj);
+}
- void disconnect();
+/// Return an instance
+std::auto_ptr<as_object> init_mysql_instance();
- MYSQL* m_db;
- };
+}
+// __MYSQL_DB_H__
+#endif
-}
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
-#endif // SWF_DBGRID_H
Index: extensions/mysql/Makefile.am
===================================================================
RCS file: extensions/mysql/Makefile.am
diff -N extensions/mysql/Makefile.am
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ extensions/mysql/Makefile.am 15 Dec 2006 20:51:43 -0000 1.1
@@ -0,0 +1,54 @@
+## Process this file with automake to generate Makefile.in
+#
+# Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+AUTOMAKE_OPTIONS =
+
+# this is where Gnash plugins get installed
+pluginsdir = $(libdir)/gnash/plugins
+
+plugins_LTLIBRARIES = mysql.la
+
+AM_CPPFLAGS = -I$(srcdir) \
+ -I$(top_srcdir)/libbase \
+ -I$(top_srcdir)/server \
+ -I$(top_srcdir)/server/vm \
+ -I$(top_srcdir)/asobjs \
+ $(MYSQLCLIENT_CFLAGS)
+
+AM_LDFLAGS = \
+ $(MYSQLCLIENT_LIBS) \
+ $(top_builddir)/server/vm/libgnashvm.la \
+ $(top_builddir)/backend/libgnashbackend.la \
+ $(top_builddir)/server/libgnashserver.la \
+ $(PTHREAD_LIBS) \
+ $(NULL)
+
+mysql_la_SOURCES = mysql_db.cpp mysql_db.h
+mysql_la_LDFLAGS = -module -avoid-version # -no-undefined
+mysql_la_LIBDADD = $(AM_LDFLAGS)
+
+CLEANFILES = \
+ gnash-dbg.log
+
+# SharedTest_SOURCES = SharedTest.cpp
+# SharedTest_CPPFLAGS = '-DINPUT="$(srcdir)/SharedTest.cpp"'
+# SharedTest_LDFLAGS = -export-dynamic
+
+install-pluginsLTLIBRARIES: $(plugins_LTLIBRARIES)
+ test -d "$(DESTDIR)$(pluginsdir)" || $(mkinstalldirs)
"$(DESTDIR)$(pluginsdir)"
+ $(LIBTOOL) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG)
$(plugins_LTLIBRARIES) "$(DESTDIR)$(pluginsdir)/$(plugins_LTLIBRARIES)"
+ $(RM) $(DESTDIR)$(pluginsdir)/*.a
Index: extensions/mysql/test.as
===================================================================
RCS file: extensions/mysql/test.as
diff -N extensions/mysql/test.as
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ extensions/mysql/test.as 15 Dec 2006 20:51:43 -0000 1.1
@@ -0,0 +1,101 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// compile this test case with Ming makeswf, and then
+// execute it like this gnash -1 -r 0 -v out.swf
+
+rcsid="$Id: test.as,v 1.1 2006/12/15 20:51:43 rsavoye Exp $";
+
+var runtest = new DejaGnu();
+var db = new MySQL();
+
+// See if the new AS class and it's methods exist
+if (db) {
+ runtest.pass("DejaGnu() constructor");
+} else {
+ runtest.fail("DejaGnu() constructor");
+}
+
+if (db.connect) {
+ runtest.pass("MySQL::connect exists");
+} else {
+ runtest.fail("MySQL::connect doesn't exist");
+}
+
+// if (db.getData) {
+// runtest.pass("MySQL::getData exists");
+// } else {
+// runtest.fail("MySQL::getData doesn't exist");
+// }
+
+if (db.disconnect) {
+ runtest.pass("MySQL::disconnect exists");
+} else {
+ runtest.fail("MySQL::disconnect doesn't exist");
+}
+
+// See if the API minimally works
+if (db.connect("localhost", "gnash", "gnash", "gnash")) {
+ runtest.pass("MySQL::connect connects");
+} else {
+ runtest.fail("MySQL::connect doesn't connect");
+}
+
+var arr1 = new Array();
+var arr2 = new Array();
+
+if (db.query("SELECT * from test;")) {
+ runtest.pass("MySQL::query works");
+} else {
+ runtest.fail("MySQL::query doesn't work");
+}
+
+if (db.store_results()) {
+ runtest.pass("MySQL::store_results works");
+} else {
+ runtest.fail("MySQL::store_results doesn't work");
+}
+
+if (db.num_fields() > 0) {
+ runtest.pass("MySQL::num_fields works");
+} else {
+ runtest.fail("MySQL::num_fields doesn't work");
+}
+
+arr1 = db.fetch_row();
+trace(arr1[0]);
+
+if (db.qetData("SELECT * from test;", arr2)) {
+ runtest.pass("MySQL::qetData works");
+} else {
+ runtest.fail("MySQL::qetData doesn't work");
+}
+
+for (i=0; i<arr2.size(); i++) {
+ trace(arr2[i]);
+}
+trace(arr2[0]);
+trace(arr2[1]);
+
+// all done
+if (db.disconnect()) {
+ runtest.pass("MySQL::disconnect disconnects");
+} else {
+ runtest.fail("MySQL::disconnect doesn't disconnect");
+}
+
Index: extensions/mysql/test.sql
===================================================================
RCS file: extensions/mysql/test.sql
diff -N extensions/mysql/test.sql
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ extensions/mysql/test.sql 15 Dec 2006 20:51:43 -0000 1.1
@@ -0,0 +1,47 @@
+-- MySQL dump 10.10
+--
+-- Host: localhost Database: gnash
+-- ------------------------------------------------------
+-- Server version 5.0.22
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `test`
+--
+
+DROP TABLE IF EXISTS `test`;
+CREATE TABLE `test` (
+ `test-name` char(60) character set latin1 collate latin1_bin NOT NULL
default '',
+ `test-type` char(20) character set latin1 collate latin1_bin NOT NULL
default ''
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+--
+-- Dumping data for table `test`
+--
+
+
+/*!40000 ALTER TABLE `test` DISABLE KEYS */;
+LOCK TABLES `test` WRITE;
+INSERT INTO `test` VALUES
('foobar','arg'),('barfoo','gra'),('foo','bar'),('bar','foo'),('bar foo','foo
bar');
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `test` ENABLE KEYS */;
+/*!40103 SET address@hidden */;
+
+/*!40101 SET address@hidden */;
+/*!40014 SET address@hidden */;
+/*!40014 SET address@hidden */;
+/*!40101 SET address@hidden */;
+/*!40101 SET address@hidden */;
+/*!40101 SET address@hidden */;
+/*!40111 SET address@hidden */;
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash server/array.cpp ChangeLog extensions/dej...,
Rob Savoye <=