2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "mysql_table.h"
25 using namespace gnash
;
27 as_value
size_method(const fn_call
& fn
)
29 assert(fn
.this_ptr
); assert(fn
.env
);
30 table
* tbl
= (table
*) (as_object
*) fn
.this_ptr
;
31 return as_value(tbl
->size());
34 table::table(MYSQL_RES
* result
)
36 as_object::set_member("size", &size_method
);
39 MYSQL_FIELD
* fld
= mysql_fetch_fields(result
);
40 int num_fields
= mysql_num_fields(result
);
41 int num_rows
= mysql_num_rows(result
);
43 m_data
.resize(num_rows
);
44 for (int i
= 0; i
< num_rows
; i
++)
46 MYSQL_ROW row
= mysql_fetch_row(result
);
48 m_data
[i
] = new as_object();
51 for (int j
= 0; j
< num_fields
; j
++)
63 case MYSQL_TYPE_SHORT
:
64 case MYSQL_TYPE_INT24
:
65 val
.set_int(stroul(row
[j
], NULL
, 0));
68 case MYSQL_TYPE_DECIMAL
:
70 case MYSQL_TYPE_FLOAT
:
71 case MYSQL_TYPE_DOUBLE
:
72 case MYSQL_TYPE_LONGLONG
:
73 val
.set_double(strtod(row
[j
], NULL
));
77 case MYSQL_TYPE_TIMESTAMP
:
80 case MYSQL_TYPE_DATETIME
:
82 case MYSQL_TYPE_NEWDATE
:
83 case MYSQL_TYPE_VARCHAR
:
85 case MYSQL_TYPE_NEWDECIMAL
:
88 case MYSQL_TYPE_TINY_BLOB
:
89 case MYSQL_TYPE_MEDIUM_BLOB
:
90 case MYSQL_TYPE_LONG_BLOB
:
92 case MYSQL_TYPE_VAR_STRING
:
93 case MYSQL_TYPE_STRING
:
94 case MYSQL_TYPE_GEOMETRY
:
95 val
.set_string(row
[j
]);
99 m_data
[i
]->set_member(fld
[j
].name
, val
);
106 for (int i
= 0; i
< size(); i
++)
108 m_data
[i
]->drop_ref();
112 bool table::get_member(const std::string
& name
, as_value
* val
)
114 // check table methods
115 if ( as_object::get_member(name
, val
) == false )
118 int idx
= strtoul(name
.c_str(), NULL
, 0);
119 if (idx
>=0 && idx
< size())
125 val
->set_undefined();
133 return m_data
.size();
136 } // end of namespace mysqldb