~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to extensions/mysql/mysql_table.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
// 
 
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.
 
8
// 
 
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.
 
13
// 
 
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
 
17
 
 
18
#include "as_value.h"
 
19
#include "fn_call.h"
 
20
#include "mysql_table.h"
 
21
 
 
22
namespace mysqldb
 
23
{
 
24
        using namespace gnash;
 
25
 
 
26
        as_value        size_method(const fn_call& fn)
 
27
        {
 
28
                assert(fn.this_ptr);    assert(fn.env);
 
29
                table* tbl = (table*) (as_object*) fn.this_ptr;
 
30
                return as_value(tbl->size());
 
31
        }
 
32
 
 
33
        table::table(MYSQL_RES* result)
 
34
        {
 
35
                as_object::set_member("size", &size_method);
 
36
 
 
37
          // retrieve data
 
38
                MYSQL_FIELD* fld = mysql_fetch_fields(result);
 
39
                int num_fields = mysql_num_fields(result);
 
40
                int num_rows =  mysql_num_rows(result);
 
41
                
 
42
                m_data.resize(num_rows);
 
43
                for (int i = 0; i < num_rows; i++)
 
44
                {
 
45
                        MYSQL_ROW row = mysql_fetch_row(result);
 
46
 
 
47
                        m_data[i] = new as_object();
 
48
                        m_data[i]->add_ref();
 
49
 
 
50
                        for (int j = 0; j < num_fields; j++)
 
51
                        {
 
52
                                as_value val;
 
53
                                if (row[j] == NULL)
 
54
                                {
 
55
                                        val.set_null();
 
56
                                }
 
57
                                else
 
58
                                {
 
59
                                        switch (fld[j].type)
 
60
                                        {
 
61
                                                case MYSQL_TYPE_TINY:
 
62
                                                case MYSQL_TYPE_SHORT:
 
63
                                                case MYSQL_TYPE_INT24:
 
64
                                                        val.set_int(stroul(row[j], NULL, 0));
 
65
                                                        break;
 
66
 
 
67
                                                case MYSQL_TYPE_DECIMAL:
 
68
                                                case MYSQL_TYPE_LONG:
 
69
                                                case MYSQL_TYPE_FLOAT:
 
70
                                                case MYSQL_TYPE_DOUBLE:
 
71
                                                case MYSQL_TYPE_LONGLONG:
 
72
                                                        val.set_double(strtod(row[j], NULL));
 
73
                                                        break;
 
74
 
 
75
                                                case MYSQL_TYPE_NULL:
 
76
                                                case MYSQL_TYPE_TIMESTAMP:
 
77
                                                case MYSQL_TYPE_DATE:
 
78
                                                case MYSQL_TYPE_TIME:
 
79
                                                case MYSQL_TYPE_DATETIME:
 
80
                                                case MYSQL_TYPE_YEAR:
 
81
                                                case MYSQL_TYPE_NEWDATE:
 
82
                                                case MYSQL_TYPE_VARCHAR:
 
83
                                                case MYSQL_TYPE_BIT:
 
84
                                                case MYSQL_TYPE_NEWDECIMAL:
 
85
                                                case MYSQL_TYPE_ENUM:
 
86
                                                case MYSQL_TYPE_SET:
 
87
                                                case MYSQL_TYPE_TINY_BLOB:
 
88
                                                case MYSQL_TYPE_MEDIUM_BLOB:
 
89
                                                case MYSQL_TYPE_LONG_BLOB:
 
90
                                                case MYSQL_TYPE_BLOB:
 
91
                                                case MYSQL_TYPE_VAR_STRING:
 
92
                                                case MYSQL_TYPE_STRING:
 
93
                                                case MYSQL_TYPE_GEOMETRY:
 
94
                                                        val.set_string(row[j]);
 
95
                                                        break;
 
96
                                        }
 
97
                                }
 
98
                                m_data[i]->set_member(fld[j].name, val);
 
99
                        }
 
100
                }
 
101
        }
 
102
 
 
103
        table::~table()
 
104
        {
 
105
                for (int i = 0; i < size(); i++)
 
106
                {
 
107
                        m_data[i]->drop_ref();
 
108
                }
 
109
        }
 
110
 
 
111
        bool    table::get_member(const std::string& name, as_value* val)
 
112
        {
 
113
                // check table methods
 
114
                if ( as_object::get_member(name, val) == false )
 
115
                {
 
116
                        // hack
 
117
                        int idx = strtoul(name.c_str(), NULL, 0);
 
118
                        if (idx >=0 && idx < size())
 
119
                        {
 
120
                                *val = m_data[idx];
 
121
                        }
 
122
                        else
 
123
                        {
 
124
                                val->set_undefined();
 
125
                        }
 
126
                }
 
127
                return true;
 
128
        }
 
129
 
 
130
        int table::size()
 
131
        {
 
132
                return m_data.size();
 
133
        }
 
134
 
 
135
}       //      end of namespace mysqldb