Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seg fault in Native API #122

Open
smkniazi opened this issue Apr 6, 2022 · 0 comments
Open

Seg fault in Native API #122

smkniazi opened this issue Apr 6, 2022 · 0 comments

Comments

@smkniazi
Copy link
Collaborator

smkniazi commented Apr 6, 2022

I get seg fault using the following API when aValue is greater in length of the column.

NdbOperation::equal(const char* anAttrName, const char* aValue)
NdbOperation::equal(const char* anAttrName, const char* aValue, Uint32 len)

Table def

CREATE TABLE `chartable` (                                            
  `id` char(5) NOT NULL,                                              
  `value` char(5) DEFAULT NULL,                                       
  PRIMARY KEY (`id`)                                                  
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
int main(int argc, char **argv) {
  char connection_string[] = "localhost:1186";
  Init(connection_string);

  Ndb *ndb_object  = nullptr;
  RS_Status status = GetNDBObject(ndb_connection, &ndb_object);

  ndb_object->setCatalogName("test");
  const NdbDictionary::Dictionary *dict = ndb_object->getDictionary();
  const NdbDictionary::Table *table     = dict->getTable("chartable");
  const NdbDictionary::Column *col      = table->getColumn("id");

  NdbTransaction *transaction = ndb_object->startTransaction(table);
  if (transaction == nullptr) {
    std::cout << "Tx Start failed" << std::endl;
  }

  NdbOperation *operation = transaction->getNdbOperation(table);
  if (operation == nullptr) {
    std::cout << "get operation failed" << std::endl;
  }
  operation->readTuple(NdbOperation::LM_CommittedRead);


  // char pk[col->getLength()];
  // for (int i = 0; i < col->getLength(); i++) {
    // pk[i] = 0;
  // }
  std::string pkstr = "000000000000000000000000000000000000000000";
  // std::memcpy(pk, pkstr.c_str(), pkstr.length());
    // std::cout << "mem copy workd" << std::endl;


  int ret = operation->equal("id", pkstr.c_str(), pkstr.length());
  if (ret != 0) {
    std::cout << "Op equal failed" << std::endl;
  }

  NdbRecAttr *val_rec = operation->getValue("value", NULL);

  ret = transaction->execute(NdbTransaction::Commit);
  if (ret != 0) {
    std::cout << "execute failed" << std::endl;
  }

  if (transaction->getNdbError().classification == NdbError::NoDataFound) {
    std::cout << "NOT FOUND" << std::endl;
  } else {
    std::cout << "data: " << val_rec->aRef() << std::endl;
  }
  ndb_object->closeTransaction(transaction);
  CloseNDBObject(&ndb_object);
  Shutdown();
  return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant