Пример #1
0
int64_t Database::insert(const String &table, const Serializable &serializable)
{
	Statement dummy = prepare("SELECT * FROM `" + table + "` LIMIT 1");
	dummy.step();

	String columns;
	String values;

	int count = 0;
	for(int i=0; i<dummy.columnsCount(); ++i)
	{
		String name = dummy.name(i);
		if(name == "rowid" || name == "id")
			continue;

		if(count)
		{
			columns+= ',';
			values+= ',';
		}
		columns+= name;
		values+= "@" + name;

		++count;
	}

	dummy.finalize();

	String request = "INSERT OR REPLACE INTO `" + table + "` (" + columns + ") VALUES (" + values + ")";
	Statement statement = prepare(request);
	statement << serializable;
	statement.execute();	// unbound parameters will be interpreted as null

	return insertId();
}
Пример #2
0
void Account::setName(const QString& name) {
    if (findAccount() == this) {
        removeId();
    }
    m_name = name;
    insertId();
    changed();
}
Пример #3
0
void Account::insert(Account *account, int index) {
    Q_ASSERT(account);
    int i = index == -1 ? m_accountList.count() : index;
    m_accountList.insert(i, account);
    account->setList(m_list);
    account->setParent(this);
    insertId(account);
    account->insertChildren();
}
Пример #4
0
 foreach (Account *a, m_accountList) {
     a->setList(m_list);
     a->setParent(this);
     insertId(a);
     a->insertChildren();
 }
Пример #5
0
void runClient(int sockfd, const char* server, unsigned port)
{
  char input[BUFFER_SIZE];
  char output = CLI_EXIT_MSG;
  char* idStr = NULL;
  char* data = NULL;
  unsigned id = 0;
  unsigned countId = 0;
  int numDigits = 0;
  fd_set fds;
  
  if(sockfd == -1)
    return;

  FD_ZERO(&fds);

  printf(WELCOME_MSG, server, port);

  while(1) {
    FD_SET(sockfd, &fds);

    fgets(input, BUFFER_SIZE, stdin);

    if(strncasecmp("help", input, strlen("help")) == 0) {
      printf(HELP_MSG);
    } else if(strlen(input) > 6) {
      input[6] = '\0'; /* All commands should have a space here */
      idStr = input+7;
      id = atoi(idStr);
      countId = id;

      /* Count number of char's for id */
      numDigits = 0;
      while(countId) { /* In base 10 */
        countId /= 10;
        numDigits++;
      }

      data = idStr + numDigits + 1; /* If needed */

      /* Determine what we want to do */
      if(strncasecmp(input, "insert", strlen("insert")) == 0) {
        output = CLI_INS_MSG;
      } else if(strncasecmp(input, "remove", strlen("remove")) == 0) {
        output = CLI_REM_MSG;
      } else if(strncasecmp(input, "lookup", strlen("lookup")) == 0) {
        output = CLI_FIND_MSG;
      }

      select(sockfd+1, NULL, &fds, NULL, NULL);
      sendData(sockfd, &output, sizeof(output));

      switch(output)
      {
        default:
          /* Do nothing */
          break;
        case CLI_INS_MSG:
          insertId(sockfd, id, data);
          break;
        case CLI_REM_MSG:
          removeId(sockfd, id);
          break;
        case CLI_FIND_MSG:
          /* Need to actually display this information if valid */
          lookupId(sockfd, id);
          break;
      }

    } else if(strncasecmp("exit", input, strlen("exit")) == 0) {
      output = CLI_EXIT_MSG;
      sendData(sockfd, &output, sizeof(output));
      break;
    } else {
      fprintf(stderr, "Unknown command\n");
    }
  }
}