Esempio n. 1
0
    HEGGQUERY
get_query (InputStruct* inputStruct)
{
    HEGGQUERY egg_query = NULL;
    if(inputStruct->keywords != NULL)
    {
        egg_query = add_query(egg_query, "keywords", inputStruct->keywords);
    }
    if(inputStruct->category != NULL)
    {
        egg_query = add_query(egg_query, "category", inputStruct->category);
    }
    return egg_query;
}		/* -----  end of function get_query  ----- */
Esempio n. 2
0
void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry) {
  // Verification step
  // If RA, Dec are Null, it denotes an invalid object and should not be written

  if (catalog_entry.ra == KSParser::EBROKEN_DOUBLE ||
      catalog_entry.ra == 0.0 ||
      catalog_entry.dec == KSParser::EBROKEN_DOUBLE ||
      catalog_entry.dec == 0.0) {
    kDebug() << "Attempt to add incorrect ra & dec with ID:"
             << catalog_entry.ID << " Long Name: "
             << catalog_entry.long_name;
    return;
  }
  // Part 1: Adding in DSO table
  // I will not use QSQLTableModel as I need to execute a query to find
  // out the lastInsertId

  // Part 2: Fuzzy Match or Create New Entry
  int rowuid = FindFuzzyEntry(catalog_entry.ra, catalog_entry.dec,
                              catalog_entry.magnitude);
  int catid;

  skydb_.open();
  if ( rowuid == -1) { //i.e. No fuzzy match found. Proceed to add new entry
    QSqlQuery add_query(skydb_);
    add_query.prepare("INSERT INTO DSO (RA, Dec, Type, Magnitude, PositionAngle,"
                      " MajorAxis, MinorAxis, Flux) VALUES (:RA, :Dec, :Type,"
                      " :Magnitude, :PositionAngle, :MajorAxis, :MinorAxis,"
                      " :Flux)");
    add_query.bindValue("RA", catalog_entry.ra);
    add_query.bindValue("Dec", catalog_entry.dec);
    add_query.bindValue("Type", catalog_entry.type);
    add_query.bindValue("Magnitude", catalog_entry.magnitude);
    add_query.bindValue("PositionAngle", catalog_entry.position_angle);
    add_query.bindValue("MajorAxis", catalog_entry.major_axis);
    add_query.bindValue("MinorAxis", catalog_entry.minor_axis);
    add_query.bindValue("Flux", catalog_entry.flux);
    if (!add_query.exec()) {
      kWarning() << "Custom Catalog Insert Query FAILED!";
      kWarning() << add_query.lastQuery();
    }

    // Find UID of the Row just added
    rowuid = add_query.lastInsertId().toInt();
    add_query.clear();
  }

  /* TODO(spacetime)
   * Possible Bugs in QSQL Db with SQLite
   * 1) Unless the db is closed and opened again, the next queries
   *    fail.
   * 2) unless I clear the resources, db close fails. The doc says
   *    this is to be rarely used.
   */

  // Find ID of catalog
  skydb_.close();
  catid = FindCatalog(catalog_entry.catalog_name);

  // Part 3: Add in Object Designation
  skydb_.open();
  QSqlQuery add_od(skydb_);
  add_od.prepare("INSERT INTO ObjectDesignation (id_Catalog, UID_DSO, LongName"
                 ", IDNumber) VALUES (:catid, :rowuid, :longname, :id)");
  add_od.bindValue("catid", catid);
  add_od.bindValue("rowuid", rowuid);
  add_od.bindValue("longname", catalog_entry.long_name);
  add_od.bindValue("id", catalog_entry.ID);
  if (!add_od.exec()) {
    kWarning() << add_od.lastQuery();
    kWarning() << skydb_.lastError();
  }
  add_od.clear();

  skydb_.close();
}
Esempio n. 3
0
File: isql.c Progetto: nevali/libsql
static int
parse_query(const char *buf)
{
	size_t l;
	char *p, *qs;
	
	pquery_count = 0;
	if(buf)
	{
		l = strlen(buf);
		if(l + query_len + 1 > query_alloc)
		{
			query_alloc = (((query_len + l + 1) / QUERY_BLOCK) + 1) * QUERY_BLOCK;
			p = (char *) realloc(query_buf, query_alloc);
			if(!p)
			{
				fprintf(stderr, "%s: failed to allocate %u bytes for query buffer\n", short_program_name, (unsigned) query_alloc);
				exit(EXIT_FAILURE);
			}
			query_buf = p;		
		}
		p = &(query_buf[query_len]);
		strcpy(p, buf);
		query_len += l;
	}
	p = query_buf;
	query_state = 0;

	/* The state-keeping algorithm is fairly simplistic; although it only
	 * needs to care about quoting, it should (and doesn't yet) handle
	 * nesting properly, which is why it doesn't attempt to deal with
	 * parentheses at all.
	 */
	while(*p)
	{
		switch(query_state)
		{
		case 0:
			if(isspace(*p) || *p == '\r' || *p == '\n')
			{
				p++;
				break;
			}
			qs = p;
			switch(*p)
			{
				case '\'':
				case '"':
					query_state = *p;
					break;
				case '\\':
					if(p[1] == 'g' || p[1] == 'G')
					{
						p++;
						break;
					}
					qs = p;
					query_state = 2;					
					break;
				case ';':
					break;
				default:
					query_state = 1;
					break;
			}
			p++;
			break;
		case 1:
			if(*p == ';')
			{
				add_query(qs, *p);
				*p = 0;
				query_state = 0;
				p++;
				break;
			}
			if(p[0] == '\\' && p[1] == 'g')
			{
				add_query(qs, p[1]);
				*p = 0;
				query_state = 0;
				p += 2;
				break;
			}
			if(p[0] == '\\' && p[1] == 'G')
			{
				add_query(qs, p[1]);
				*p = 0;
				query_state = 0;
				p += 2;
				break;
			}
			switch(*p)
			{
				case '\'':
				case '"':
				case '`':
				case '{':
				case '[':
					query_state = *p;
					break;
			}
			p++;
			break;
		case 2:
			/* Built-in commands */
			p++;
			break;
		case '\'':
		case '"':
		case '`':
			if(*p == query_state)
			{
				query_state = 1;
			}
			p++;
			break;
		case '{':
			if(*p == '}')
			{
				query_state = 1;
			}
			p++;
			break;
		case '[':
			if(*p == ']')
			{
				query_state = 1;
			}
			p++;
			break;
		}
	}
	if(query_state == 2)
	{
		/* Trim any trailing whitespace before adding to the query list */
		p--;
		while(p > qs)
		{
			if(!isspace(*p) && *p != '\r' && *p != '\n')
			{
				break;
			}
			*p = 0;
			p--;
		}
		add_query(qs, 0);
		query_state = 0;
	}
	if(!query_state)
	{
		query_len = 0;
	}
	return query_state;
}