make (array) of ArrayObject return the contents
[hiphop-php.git] / hphp / util / dataset.h
blob34e0f874867fdd943e0444d3cd34dae5baca42a9
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_DATASET_H_
18 #define incl_HPHP_DATASET_H_
20 #include "hphp/util/base.h"
21 #include "mysql.h"
23 namespace HPHP {
25 DECLARE_BOOST_TYPES(DataSet);
26 ///////////////////////////////////////////////////////////////////////////////
28 /**
29 * A class that stores a list of rows, so that one can iterate through them by
31 * int fieldIndex = ds.getFieldIndex("id");
32 * for (ds.moveFirst(); ds.getRow(0); ds.moveNext()) {
33 * const char *value = ds.getField(0);
34 * unsigned int n = ds.getUIntField(fieldIndex);
35 * }
37 class DataSet {
38 public:
39 virtual ~DataSet() {}
41 /**
42 * Close dataset and free up resources.
44 virtual void close() = 0;
46 /**
47 * Informational functions.
49 virtual int getRowCount() const = 0;
50 virtual int getColCount() const = 0;
51 virtual int getFieldIndex(const char *fieldName) = 0;
52 virtual MYSQL_FIELD *getFields() const = 0;
54 /**
55 * Iteration functions.
57 virtual void moveFirst() = 0;
58 virtual MYSQL_ROW getRow() const = 0;
59 virtual void moveNext() = 0;
61 /**
62 * Field value retrieval.
64 virtual const char *getField(int field) const = 0;
65 virtual int getFieldLength(int field) const = 0;
66 const char *getStringField(int field) const; // NULL will become ""
67 int getIntField(int field) const;
68 unsigned int getUIntField(int field) const;
69 long long getInt64Field(int field) const;
70 unsigned long long getUInt64Field(int field) const;
72 /**
73 * Returns a one-liner of all fields of current row.
75 std::string getRowString() const;
77 private:
78 /**
79 * Helper function for getRowString().
81 static std::string escape(const char *s);
84 ///////////////////////////////////////////////////////////////////////////////
87 #endif // incl_HPHP_DATASET_H_