Giter Site home page Giter Site logo

cpp-active-record's People

Contributors

joeyates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-active-record's Issues

SQLite - TableSet::update_table(...) always throwing (tries to drop primary key)

Reference:

table_set.cpp:68 
void TableSet::update_table( Table &required ) 

required.fields() and existing.fields() will always be different because of the automatic primary key assignment. Using the example table below:

td.fields() = fields
        ("code",        ActiveRecord::text)
        ("title",       ActiveRecord::text);

required.fields() will contain: [code, title]
existing.fields() will contain: [id, code, title]

Thus, the set difference required.fields() - existing.fields() will always return the primary key id and try to drop it.

Proposed solution:

void TableSet::update_table( Table &required ) {
  log( "TableSet::update_table" );
  log( required.table_name() );
  Table existing = table_data( required.connection(), required.table_name() );
  Fields missing = required.fields() - existing.fields();
  Fields remove  = existing.fields() - required.fields();
  for( Fields::iterator it = missing.begin(); it != missing.end(); ++it )
    existing.add_field( *it );
  for( Fields::iterator it = remove.begin(); it != remove.end(); ++it ) {
    if ((*it).name() == existing.primary_key()) /* fix */
      continue;
    throw ActiveRecordException( "Table::remove_field not yet implemented", __FILE__, __LINE__ );
    //existing.remove_field( *it );
  }
}

Better solution:

The fields() method should always return the same Fields no matter the context (ie. database fetch or class). The TableSet::table_data function should not load the primary key as a Field but instead only set the id_ variable of the Table. Of course I say this without fully understanding the impact, but hopefully you agree with keeping everything deterministic.

AR_HAS_MANY(...) macro generates compiler errors

When compiling, from the master branch, the unit tests fail when resolving and compiling the AR_HAS_MANY macro:

include/active_record/base.h:30:59: error: declaration of ‘std::vector<T1>    ActiveRecord::Base<T>::has_many()’ outside of class is not definition [-fpermissive]
 vector< other > ActiveRecord::Base< owner >::has_many(); \
                                                       ^
test/base_associations_test.cpp:29:1: note: in expansion of macro ‘AR_HAS_MANY’
 AR_HAS_MANY( Library, Book )

gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

Uncaught exception

base.h
bool load();

stringstream is alive and used when throwing exception.
During throwing exception and memory deployment we have "Aborted".
This one works fine

template <class T>
bool Base<T>::load() {
  {
      std::stringstream ss;
      ss << "SELECT * ";
      ss << "FROM " << table_name_ << " ";
      ss << "WHERE ";
      ss << primary_key_ << " = ?";

      AttributeList parameters;
      parameters.push_back(id());

      Row row = connection_->select_one(ss.str(), parameters);
      if(row.has_data())
      {
          attributes_ = row.attributes();
          state_ = loaded;
          return true;
      }
  }
  throw ActiveRecordException("Record not found", __FILE__, __LINE__);
  return false;
}

Using sqlite3 int64_t value type

Hello!
In your code of sqlite3_attribute.cpp we can see something like this:

// TYPE_LIST
  if(strcasecmp(type, "INTEGER") == 0) {
    return static_cast<int64_t>(sqlite3_column_int(pStmt, i));
  }

But if we ask https://www.sqlite.org we can get something like this:
SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
Of course we haven't int64_t becouse we have int
We can use something like this:
SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
And finally:

// TYPE_LIST
  if(strcasecmp(type, "INTEGER") == 0) {
    return sqlite3_column_int64(pStmt, i);
  }

And also in sqlite3_connection.cpp

case Type::integer: {
        int64_t value = boost::get<int64_t>(parameter);
        pa.param_values[i] = nullptr;
        sqlite3_bind_int(ppStmt, i + 1, value);
        break;
      }

We must use sqlite3_bind_int64
Done)
This library is very useful for me. And I hope that we can make it even better.
Thanks)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.