2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include "mysql_table.h"
24
using namespace gnash;
26
as_value size_method(const fn_call& fn)
28
assert(fn.this_ptr); assert(fn.env);
29
table* tbl = (table*) (as_object*) fn.this_ptr;
30
return as_value(tbl->size());
33
table::table(MYSQL_RES* result)
35
as_object::set_member("size", &size_method);
38
MYSQL_FIELD* fld = mysql_fetch_fields(result);
39
int num_fields = mysql_num_fields(result);
40
int num_rows = mysql_num_rows(result);
42
m_data.resize(num_rows);
43
for (int i = 0; i < num_rows; i++)
45
MYSQL_ROW row = mysql_fetch_row(result);
47
m_data[i] = new as_object();
50
for (int j = 0; j < num_fields; j++)
62
case MYSQL_TYPE_SHORT:
63
case MYSQL_TYPE_INT24:
64
val.set_int(stroul(row[j], NULL, 0));
67
case MYSQL_TYPE_DECIMAL:
69
case MYSQL_TYPE_FLOAT:
70
case MYSQL_TYPE_DOUBLE:
71
case MYSQL_TYPE_LONGLONG:
72
val.set_double(strtod(row[j], NULL));
76
case MYSQL_TYPE_TIMESTAMP:
79
case MYSQL_TYPE_DATETIME:
81
case MYSQL_TYPE_NEWDATE:
82
case MYSQL_TYPE_VARCHAR:
84
case MYSQL_TYPE_NEWDECIMAL:
87
case MYSQL_TYPE_TINY_BLOB:
88
case MYSQL_TYPE_MEDIUM_BLOB:
89
case MYSQL_TYPE_LONG_BLOB:
91
case MYSQL_TYPE_VAR_STRING:
92
case MYSQL_TYPE_STRING:
93
case MYSQL_TYPE_GEOMETRY:
94
val.set_string(row[j]);
98
m_data[i]->set_member(fld[j].name, val);
105
for (int i = 0; i < size(); i++)
107
m_data[i]->drop_ref();
111
bool table::get_member(const std::string& name, as_value* val)
113
// check table methods
114
if ( as_object::get_member(name, val) == false )
117
int idx = strtoul(name.c_str(), NULL, 0);
118
if (idx >=0 && idx < size())
124
val->set_undefined();
132
return m_data.size();
135
} // end of namespace mysqldb