View | Details | Raw Unified | Return to bug 2480
Collapse All | Expand All

(-)a/src/stats/model/sqlite-data-output.cc (-53 / +78 lines)
 Lines 126-151    Link Here 
126
      return;
126
      return;
127
    }
127
    }
128
128
129
  Exec ("create table if not exists Experiments (run, experiment, strategy, input, description text)");
130
131
  sqlite3_stmt *stmt;
132
  sqlite3_prepare_v2 (m_db,
133
    "insert into Experiments (run, experiment, strategy, input, description) values (?, ?, ?, ?, ?)",
134
    -1,
135
    &stmt,
136
    NULL
137
  );
138
129
  std::string run = dc.GetRunLabel ();
139
  std::string run = dc.GetRunLabel ();
130
140
  sqlite3_bind_text (stmt, 1, run.c_str (), run.length (), SQLITE_TRANSIENT);
131
  Exec ("create table if not exists Experiments (run, experiment, strategy, input, description text)");
141
  sqlite3_bind_text (stmt, 2, dc.GetExperimentLabel ().c_str (),
132
  Exec ("insert into Experiments (run,experiment,strategy,input,description) values ('" +
142
                              dc.GetExperimentLabel ().length (), SQLITE_TRANSIENT);
133
        run + "', '" +
143
  sqlite3_bind_text (stmt, 3, dc.GetStrategyLabel ().c_str (),
134
        dc.GetExperimentLabel () + "', '" +
144
                              dc.GetStrategyLabel ().length (), SQLITE_TRANSIENT);
135
        dc.GetStrategyLabel () + "', '" +
145
  sqlite3_bind_text (stmt, 4, dc.GetInputLabel ().c_str (),
136
        dc.GetInputLabel () + "', '" +
146
                              dc.GetInputLabel ().length (), SQLITE_TRANSIENT);
137
        dc.GetDescription () + "')");
147
  sqlite3_bind_text (stmt, 5, dc.GetDescription ().c_str (),
148
                              dc.GetDescription ().length (), SQLITE_TRANSIENT);
149
  sqlite3_step (stmt);
150
  sqlite3_finalize (stmt);
138
151
139
  Exec ("create table if not exists Metadata ( run text, key text, value)");
152
  Exec ("create table if not exists Metadata ( run text, key text, value)");
140
153
154
  sqlite3_prepare_v2 (m_db,
155
    "insert into Metadata (run, key, value) values (?, ?, ?)",
156
    -1,
157
    &stmt,
158
    NULL
159
  );
141
  for (MetadataList::iterator i = dc.MetadataBegin ();
160
  for (MetadataList::iterator i = dc.MetadataBegin ();
142
       i != dc.MetadataEnd (); i++) {
161
       i != dc.MetadataEnd (); i++) {
143
      std::pair<std::string, std::string> blob = (*i);
162
      std::pair<std::string, std::string> blob = (*i);
144
      Exec ("insert into Metadata (run,key,value) values ('" +
163
145
            run + "', '" +
164
      sqlite3_reset (stmt);
146
            blob.first + "', '" +
165
      sqlite3_bind_text (stmt, 1, run.c_str (),
147
            blob.second + "')");
166
                                  run.length (), SQLITE_TRANSIENT);
167
      sqlite3_bind_text (stmt, 2, blob.first.c_str (),
168
                                  blob.first.length (), SQLITE_TRANSIENT);
169
      sqlite3_bind_text (stmt, 3, blob.second.c_str (),
170
                                  blob.second.length (), SQLITE_TRANSIENT);
171
      sqlite3_step (stmt);
148
    }
172
    }
173
  sqlite3_finalize (stmt);
149
174
150
  Exec ("BEGIN");
175
  Exec ("BEGIN");
151
  SqliteOutputCallback callback (this, run);
176
  SqliteOutputCallback callback (this, run);
 Lines 169-177    Link Here 
169
194
170
  m_owner->Exec ("create table if not exists Singletons ( run text, name text, variable text, value )");
195
  m_owner->Exec ("create table if not exists Singletons ( run text, name text, variable text, value )");
171
196
197
  sqlite3_prepare_v2 (m_owner->m_db,
198
    "insert into Singletons (run, name, variable, value) values (?, ?, ?, ?)",
199
    -1,
200
    &m_insertSingletonStatement,
201
    NULL
202
  );
203
  sqlite3_bind_text (m_insertSingletonStatement, 1, m_runLabel.c_str (), m_runLabel.length (), SQLITE_TRANSIENT);
204
172
  // end SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
205
  // end SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
173
}
206
}
174
207
208
SqliteDataOutput::SqliteOutputCallback::~SqliteOutputCallback ()
209
{
210
  sqlite3_finalize (m_insertSingletonStatement);
211
}
212
175
void
213
void
176
SqliteDataOutput::SqliteOutputCallback::OutputStatistic (std::string key,
214
SqliteDataOutput::SqliteOutputCallback::OutputStatistic (std::string key,
177
                                                         std::string variable,
215
                                                         std::string variable,
 Lines 200-214    Link Here 
200
{
238
{
201
  NS_LOG_FUNCTION (this << key << variable << val);
239
  NS_LOG_FUNCTION (this << key << variable << val);
202
240
203
  std::stringstream sstr;
241
  sqlite3_reset (m_insertSingletonStatement);
204
  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
242
  sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
205
  m_runLabel << "', '" <<
243
  sqlite3_bind_text (m_insertSingletonStatement, 3, variable.c_str (), variable.length (), SQLITE_TRANSIENT);
206
  key << "', '" <<
244
  sqlite3_bind_int (m_insertSingletonStatement, 4, val);
207
  variable << "', " <<
245
  sqlite3_step (m_insertSingletonStatement);
208
  val << ")";
209
  m_owner->Exec (sstr.str ());
210
211
  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
212
}
246
}
213
void
247
void
214
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
248
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
 Lines 217-231    Link Here 
217
{
251
{
218
  NS_LOG_FUNCTION (this << key << variable << val);
252
  NS_LOG_FUNCTION (this << key << variable << val);
219
253
220
  std::stringstream sstr;
254
  sqlite3_reset (m_insertSingletonStatement);
221
  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
255
  sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
222
  m_runLabel << "', '" <<
256
  sqlite3_bind_text (m_insertSingletonStatement, 3, variable.c_str (), -1, SQLITE_TRANSIENT);
223
  key << "', '" <<
257
  sqlite3_bind_int64 (m_insertSingletonStatement, 4, val);
224
  variable << "', " <<
258
  sqlite3_step (m_insertSingletonStatement);
225
  val << ")";
226
  m_owner->Exec (sstr.str ());
227
  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
228
}
259
}
260
229
void
261
void
230
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
262
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
231
                                                         std::string variable,
263
                                                         std::string variable,
 Lines 233-247    Link Here 
233
{
265
{
234
  NS_LOG_FUNCTION (this << key << variable << val);
266
  NS_LOG_FUNCTION (this << key << variable << val);
235
267
236
  std::stringstream sstr;
268
  sqlite3_reset (m_insertSingletonStatement);
237
  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
269
  sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
238
  m_runLabel << "', '" <<
270
  sqlite3_bind_text (m_insertSingletonStatement, 3, variable.c_str (), variable.length (), SQLITE_TRANSIENT);
239
  key << "', '" <<
271
  sqlite3_bind_double (m_insertSingletonStatement, 4, val);
240
  variable << "', " <<
272
  sqlite3_step (m_insertSingletonStatement);
241
  val << ")";
242
  m_owner->Exec (sstr.str ());
243
  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
244
}
273
}
274
245
void
275
void
246
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
276
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
247
                                                         std::string variable,
277
                                                         std::string variable,
 Lines 249-263    Link Here 
249
{
279
{
250
  NS_LOG_FUNCTION (this << key << variable << val);
280
  NS_LOG_FUNCTION (this << key << variable << val);
251
281
252
  std::stringstream sstr;
282
  sqlite3_reset (m_insertSingletonStatement);
253
  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
283
  sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
254
  m_runLabel << "', '" <<
284
  sqlite3_bind_text (m_insertSingletonStatement, 3, variable.c_str (), variable.length (), SQLITE_TRANSIENT);
255
  key << "', '" <<
285
  sqlite3_bind_text (m_insertSingletonStatement, 4, val.c_str (), val.length (), SQLITE_TRANSIENT);
256
  variable << "', '" <<
286
  sqlite3_step (m_insertSingletonStatement);
257
  val << "')";
258
  m_owner->Exec (sstr.str ());
259
  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
260
}
287
}
288
261
void
289
void
262
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
290
SqliteDataOutput::SqliteOutputCallback::OutputSingleton (std::string key,
263
                                                         std::string variable,
291
                                                         std::string variable,
 Lines 265-276    Link Here 
265
{
293
{
266
  NS_LOG_FUNCTION (this << key << variable << val);
294
  NS_LOG_FUNCTION (this << key << variable << val);
267
295
268
  std::stringstream sstr;
296
  sqlite3_reset (m_insertSingletonStatement);
269
  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
297
  sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
270
  m_runLabel << "', '" <<
298
  sqlite3_bind_text (m_insertSingletonStatement, 3, variable.c_str (), variable.length (), SQLITE_TRANSIENT);
271
  key << "', '" <<
299
  sqlite3_bind_int64 (m_insertSingletonStatement, 4, val.GetTimeStep ());
272
  variable << "', " <<
300
  sqlite3_step (m_insertSingletonStatement);
273
  val.GetTimeStep () << ")";
274
  m_owner->Exec (sstr.str ());
275
  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
276
}
301
}
(-)a/src/stats/model/sqlite-data-output.h (-1 / +7 lines)
 Lines 27-33    Link Here 
27
27
28
#define STATS_HAS_SQLITE3
28
#define STATS_HAS_SQLITE3
29
29
30
struct sqlite3;
30
#include <sqlite3.h>
31
31
32
namespace ns3 {
32
namespace ns3 {
33
33
 Lines 70-75    Link Here 
70
    SqliteOutputCallback(Ptr<SqliteDataOutput> owner, std::string run);
70
    SqliteOutputCallback(Ptr<SqliteDataOutput> owner, std::string run);
71
71
72
    /**
72
    /**
73
     * Destructor
74
     */
75
    ~SqliteOutputCallback ();
76
77
    /**
73
     * \brief Generates data statistics
78
     * \brief Generates data statistics
74
     * \param key the SQL key to use
79
     * \param key the SQL key to use
75
     * \param variable the variable name
80
     * \param variable the variable name
 Lines 132-137    Link Here 
132
private:
137
private:
133
    Ptr<SqliteDataOutput> m_owner; //!< the instance this object belongs to
138
    Ptr<SqliteDataOutput> m_owner; //!< the instance this object belongs to
134
    std::string m_runLabel; //!< Run label
139
    std::string m_runLabel; //!< Run label
140
    sqlite3_stmt *m_insertSingletonStatement; //!< Prepared singleton insert statement
135
141
136
    // end class SqliteOutputCallback
142
    // end class SqliteOutputCallback
137
  };
143
  };

Return to bug 2480