Exemplo n.º 1
0
void row_t::set_value(int id, void * ptr) {
	int datasize = get_schema()->get_field_size(id);
	int pos = get_schema()->get_field_index(id);
  DEBUG("set_value pos %d datasize %d -- %lx\n",pos,datasize,(uint64_t)this);
#if SIM_FULL_ROW
	memcpy( &data[pos], ptr, datasize);
#else
  char d[tuple_size];
	memcpy( &d[pos], ptr, datasize);
#endif
}
Exemplo n.º 2
0
static void
print_schema(const char *dev_name)
{
	nvlist_t *schema;
	const nvlist_t *iov_schema, *driver_schema, *pf_schema, *vf_schema;
	int fd;

	fd = open_device(dev_name);
	schema = get_schema(fd);

	pf_schema = nvlist_get_nvlist(schema, PF_CONFIG_NAME);
	iov_schema = nvlist_get_nvlist(pf_schema, IOV_CONFIG_NAME);
	driver_schema = nvlist_get_nvlist(pf_schema, DRIVER_CONFIG_NAME);
	printf(
"The following configuration parameters may be configured on the PF:\n");
	print_subsystem_schema(iov_schema);
	print_subsystem_schema(driver_schema);

	vf_schema = nvlist_get_nvlist(schema, VF_SCHEMA_NAME);
	iov_schema = nvlist_get_nvlist(vf_schema, IOV_CONFIG_NAME);
	driver_schema = nvlist_get_nvlist(vf_schema, DRIVER_CONFIG_NAME);
	printf(
"\nThe following configuration parameters may be configured on a VF:\n");
	print_subsystem_schema(iov_schema);
	print_subsystem_schema(driver_schema);

	nvlist_destroy(schema);
	close(fd);
}
Exemplo n.º 3
0
/* theta_type -- compute type of a theta-exp or theta-select */
PRIVATE type theta_type(tree t, env e, type a, tree cxt)
{
     def d = get_schema((tok) t->x_the_name, t->x_loc);
     schema s;
     env e1 = new_env(e);
     type b;
     int i;

     if (d == NULL)
	  return err_type;

     s = d->d_schema;
     check_rename(s, (tok) t->x_the_decor, t->x_the_rename, t);

     for (i = 0; i < s->z_ncomps; i++) {
	  sym x = s->z_comp[i].z_name;
	  sym xp = get_rename(x, (tok) t->x_the_decor, t->x_the_rename);
	  type tt = (a == NULL
		     ? ref_type(xp, nil, e, t)
		     : comp_type(a, xp, cxt, t->x_loc));
	  add_def(VAR, x, tt, e1);
     }

     b = mk_sproduct(mk_schema(e1));
     if (! aflag && d->d_abbrev && d->d_nparams == 0
	 && type_equal(b, arid, mk_sproduct(s), arid))
	  return mk_abbrev(d, arid);
     else
	  return b;
}
Exemplo n.º 4
0
/* open_sref -- find a schema and process its parameters */
PUBLIC bool open_sref(tree t, env e, def *d, frame *f)
{
     if ((*d = get_schema((tok) t->x_sref_tag, t->x_loc)) == NULL)
	  return FALSE;
     *f = mk_frame((*d)->d_nparams);
     get_params("Schema", mk_symbol((tok) t->x_sref_tag, empty),
		t->x_sref_params, e, *f, t->x_loc);
     return TRUE;
}
Exemplo n.º 5
0
void row_t::set_data(char * data) { 
	int tuple_size = get_schema()->get_tuple_size();
#if SIM_FULL_ROW
	memcpy(this->data, data, tuple_size);
#else
  char d[tuple_size];
	memcpy(d, data, tuple_size);
#endif
}
Exemplo n.º 6
0
char * row_t::get_value(char * col_name) {
  uint64_t pos __attribute__ ((unused));
	pos = get_schema()->get_field_index(col_name);
#if SIM_FULL_ROW
	return &data[pos];
#else
	return data;
#endif
}
Exemplo n.º 7
0
void row_t::set_value(int id, void * ptr, int size) {
	int pos = get_schema()->get_field_index(id);
#if SIM_FULL_ROW
	memcpy( &data[pos], ptr, size);
#else
  char d[tuple_size];
	memcpy( &d[pos], ptr, size);
#endif
}
Exemplo n.º 8
0
NPError NPN_PostURLNotify(NPP instance, const char* url, const char* target,
		uint32_t len, const char* buf, NPBool file, void* notifyData)
{
	char schema[8];
	char porttext[8];
	char hostname[256];
	char url_path[512];
	const char *partial_url;

	if (target != NULL){
		fprintf(stderr, "GetURLNotify: %s %s\n", target, url);
		return NPERR_NO_ERROR;
	}

	partial_url = get_schema(url, schema, sizeof(schema));
	partial_url = get_hostname(partial_url, hostname, sizeof(hostname));
	partial_url = get_porttext(partial_url, porttext, sizeof(porttext));
	partial_url = get_url_path(partial_url, url_path, sizeof(url_path));

	if (strncmp(schema, "http://", 7)) {
		return NPERR_GENERIC_ERROR;
	}

	char *foop;
	char headers[8192];
	NPNetStream *stream;
	proto_stream *protop;
	struct sockaddr_in name;

	name.sin_family = AF_INET;
	name.sin_port   = htons(*porttext? atoi(porttext + 1): 80);
	name.sin_addr   = inaddr_convert(hostname);

	protop = new proto_stream();
	assert(protop != NULL);

	if (protop->connect(&name, sizeof(name))) {
		protop->rel();
		return NPERR_GENERIC_ERROR;
	}

	foop = headers;
	foop += sprintf(foop, "POST %s HTTP/1.0\r\n", url_path);
	foop += sprintf(foop, "Host: %s%s\r\n", hostname, porttext);
	foop += sprintf(foop, "User-Agent: %s\r\n", NPN_UserAgent(0));
	foop += sprintf(foop, "Accept: application/xml;q=0.9,*/*,q=0.8\r\n");
	foop += sprintf(foop, "Connection: close\r\n");

	stream = new NPNetStream(instance, notifyData, url, protop);
	assert(stream != NULL);

	protop->set_request(headers, buf, len);
	stream->startup();
	protop->rel();
	return NPERR_NO_ERROR;
}
Exemplo n.º 9
0
char * row_t::get_value(int id) {
  int pos __attribute__ ((unused));
	pos = get_schema()->get_field_index(id);
  DEBUG("get_value pos %d -- %lx\n",pos,(uint64_t)this);
#if SIM_FULL_ROW
	return &data[pos];
#else
	return data;
#endif
}
Exemplo n.º 10
0
static void create_tbl ()
{
  char tbl_name[30], field_name[30], field_type[4], separator[5];
  int len;
  if ( fscanf (in_s, " table %s (", tbl_name) != 1)
    {
      put_msg (ERROR, "Do not know what to create\n");
      return;
    }

  put_msg (DEBUG, "table name: \"%s\".\n", tbl_name);

  schema_p sch = get_schema (tbl_name);
  
  if ( sch != NULL )
    {
      put_msg (ERROR, "Table \"%s\" already exists.\n", tbl_name);
      skip_line ();
      return;      
    }
  sch = new_schema (tbl_name);
  while (!feof(in_s))
    {
      fscanf (in_s, "%s %3s", field_name, field_type);
      if ( strcmp (field_type, t_int) == 0 )
	{
	  add_field ( sch, new_int_field ( field_name ));
	}
      else if ( strcmp (field_type, t_str) == 0 )
	{
	  fscanf (in_s, "(%d)", &len);
	  add_field ( sch, new_str_field ( field_name, len ));
	}
      else
	{
	  strcat (field_name, " ");
	  strcat (field_name, field_type);
	  syntax_error (field_name);
	  remove_schema (sch);
	  return;
	}
      fscanf (in_s, "%s", separator);
      put_msg(DEBUG, "seperator: \"%s\".\n", separator);
      if (separator[0] == ')')
	{
	  skip_line ();
	  break;
	}
    }
}
Exemplo n.º 11
0
Arquivo: xdr.c Projeto: GYGit/reactos
static inline xmlNsPtr get_dt_ns(xmlNodePtr node)
{
    xmlNsPtr ns;

    node = get_schema(node);
    assert(node != NULL);

    FOREACH_NS(node, ns)
    {
        if (xmlStrEqual(ns->href, DT_href))
            break;
    }

    return ns;
}
Exemplo n.º 12
0
svn_error_t *
svn_sqlite__get_schema_version(int *version,
                               const char *path,
                               apr_pool_t *scratch_pool)
{
  svn_sqlite__db_t db;

  SVN_ERR(svn_atomic__init_once(&sqlite_init_state,
                                init_sqlite, NULL, scratch_pool));
  SQLITE_ERR(sqlite3_open(path, &db.db3), &db);
  SVN_ERR(get_schema(version, &db, scratch_pool));
  SQLITE_ERR(sqlite3_close(db.db3), &db);

  return SVN_NO_ERROR;
}
Exemplo n.º 13
0
proto_stream *RedirectURLNotify(const char *url, const char *refer)
{
	char schema[8];
	char porttext[8];
	char hostname[256];
	char url_path[512];
	const char *partial_url;

	partial_url = get_schema(url, schema, sizeof(schema));
	partial_url = get_hostname(partial_url, hostname, sizeof(hostname));
	partial_url = get_porttext(partial_url, porttext, sizeof(porttext));
	partial_url = get_url_path(partial_url, url_path, sizeof(url_path));

	if (strncmp(schema, "http://", 7)) {
		return NULL;
	}

	char *foop;
	char headers[8192];
	NPNetStream *stream;
	proto_stream *protop;
	struct sockaddr_in name;

	name.sin_family = AF_INET;
	name.sin_port   = htons(*porttext? atoi(porttext + 1): 80);
	name.sin_addr   = inaddr_convert(hostname);

	protop = new proto_stream();
	assert(protop != NULL);

	if (protop->connect(&name, sizeof(name))) {
		protop->rel();
		return NULL;
	}

	foop = headers;
	foop += sprintf(foop, "GET %s HTTP/1.0\r\n", url_path);
	foop += sprintf(foop, "Host: %s%s\r\n", hostname, porttext);
	foop += sprintf(foop, "User-Agent: %s\r\n", NPN_UserAgent(0));
	foop += sprintf(foop, "Accept: application/xml;q=0.9,*/*,q=0.8\r\n");
	foop += sprintf(foop, "Refer: %s\r\n", refer);
	foop += sprintf(foop, "Connection: close\r\n");
	foop += sprintf(foop, "\r\n");

	protop->set_request(headers);
	return protop;
}
Exemplo n.º 14
0
// Main---------------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[]) {

    int repeat, aux;
    char *input;

    // A lista schema é criada e lida da stdin
    SCHEMA *schema = create_schema();
    get_schema(schema);

    do {
        // A cada repeticao le um comando da stdin
        repeat = 1;
        input = my_get_line(stdin, &aux);
        if(input == NULL) fprintf(stderr, "chamada errada\n");

        // Analisa qual o comando desejado e chama a(s) funcao(oes) responsavel(is) por realiza-lo
        if(strcmp(input, "dump_schema") == 0) {
            dump_schema(schema);
        } else if(strcmp(input, "dump_data") == 0) {
            dump_data(schema);
        } else if(strcmp(input, "dump_index") == 0) {
            print_index(schema);
        } else if(strcmp(input, "update_index") == 0) {
            get_index(schema);
            sort_index(schema);
        } else if(strcmp(input, "insert") == 0) {
            insert_data(schema);
        } else if(strcmp(input, "select") == 0) {
            search_index_data(schema);
        } else if(strcmp(input, "exit") == 0) {
            // Caso seja digitado "exit", repeat recebe 0, saindo do loop
            repeat = 0;
        }

        // A cada repeticao input eh liberado caso tenha sido alocado adequadamente
        if(input != NULL) free(input);
    } while(repeat);

    // Libera a memoria alocada
    delete_schema(&schema);

    return 0;
}
Exemplo n.º 15
0
static void insert_row ()
{
  char tbl_name[30];
	
  fscanf (in_s, " into %s values (", tbl_name);
  put_msg(DEBUG, "table name: \"%s\".\n", tbl_name);
  schema_p sch = get_schema (tbl_name);
  if (!sch)
    {
      put_msg (ERROR, "Schema \"%s\" does not exist.\n", tbl_name);
      skip_line ();
      return;
    }
  /* put_schema_info (DEBUG, sch); */
  record rec = new_filled_record ( sch );

  append_record (rec, sch);
  release_record (rec, sch);
}
Exemplo n.º 16
0
/* Check the schema format of the database, upgrading it if necessary.
   Return SVN_ERR_SQLITE_UNSUPPORTED_SCHEMA if the schema format is too new,
   or SVN_ERR_SQLITE_ERROR if an sqlite error occurs during validation.
   Return SVN_NO_ERROR if everything is okay. */
static svn_error_t *
check_format(svn_sqlite__db_t *db, int latest_schema,
             const char * const *upgrade_sql, apr_pool_t *scratch_pool)
{
  int current_schema;

  /* Validate that the schema exists as expected. */
  SVN_ERR(get_schema(&current_schema, db, scratch_pool));

  if (current_schema == latest_schema)
    return SVN_NO_ERROR;

  if (current_schema < latest_schema)
    return upgrade_format(db, current_schema, latest_schema, upgrade_sql,
                          scratch_pool);

  return svn_error_createf(SVN_ERR_SQLITE_UNSUPPORTED_SCHEMA, NULL,
                           _("Schema format %d not recognized"),
                           current_schema);
}
Exemplo n.º 17
0
static void
config_action(const char *filename, int dryrun)
{
	char *dev;
	nvlist_t *schema, *config;
	int fd;

	dev = find_device(filename);
	fd = open(dev, O_RDWR);
	if (fd < 0)
		err(1, "Could not open device '%s'", dev);

	schema = get_schema(fd);
	config = parse_config_file(filename, schema);
	if (config == NULL)
		errx(1, "Could not parse config");

	config_iov(fd, dev, config, dryrun);

	nvlist_destroy(config);
	nvlist_destroy(schema);
	free(dev);
	close(fd);
}
Exemplo n.º 18
0
void row_t::set_data(char * data) { 
	int tuple_size = get_schema()->get_tuple_size();
	memcpy(this->data, data, tuple_size);
}
Exemplo n.º 19
0
size_t database::backup(char *file)
{
	// prepare for output
	if ( get_options()&&DBO_OVERWRITE ) unlink(file);
	if ( access(file,0x00)==0 )
		exception("unable to backup of '%s' to '%s' - OVERWRITE not specified but file exists",get_schema(),file);

	// get list of tables
	MYSQL_RES *res = select("SHOW TABLES");
	if ( res==NULL )
	{
		gl_error("backup of '%s' failed - %s", file, mysql_error(mysql));
		return -1;
	}
	size_t ntables = mysql_num_rows(res);
	char **tables = new char*[ntables];
	int n;
	for ( n=0 ; n<ntables ; n++ )
	{
		MYSQL_ROW row;
		row = mysql_fetch_row(res);
		unsigned long *len = mysql_fetch_lengths(res);
		tables[n] = new char[len==NULL?1024:(len[0]+1)];
		strcpy(tables[n],row[0]);
	}
	mysql_free_result(res);

	// dump tables
	int nrows = 0;
	for ( n=0 ; n<ntables ; n++ )
	{
		size_t nr = dump(tables[n],file,TD_APPEND|TD_BACKUP);
		if ( nr<0 ) { nrows=-1; break; }
		nrows += nr;
	}
	
	for ( n=0 ; n<ntables ; n++ )
		delete [] tables[n];
	delete[] tables;
	return nrows;
}
Exemplo n.º 20
0
int database::init(OBJECT *parent)
{
	gld_string flags = get_clientflags_property().get_string();
	
	gl_verbose("mysql_connect(hostname='%s',username='******',password='******',schema='%s',port=%u,socketname='%s',clientflags=0x%016llx[%s])",
		(const char*)hostname,(const char*)username,(const char*)password,(const char*)schema,port,(const char*)socketname,get_clientflags(),(const char*)flags);

	mysql = mysql_real_connect(mysql_client,hostname,username,strcpy(password,"")?password:NULL,NULL,port,socketname,(unsigned long)clientflags);
	if ( mysql==NULL )
		exception("mysql connect failed - %s", mysql_error(mysql_client));
	else
		gl_verbose("MySQL server info: %s", mysql_get_server_info(mysql));

	// autoname schema
	if ( strcmp(get_schema(),"")==0 )
	{
		char buffer[1024];
		gld_global model("modelname");
		if ( model.to_string(buffer,sizeof(buffer))>0 )
			set_schema(buffer);
	}

	// drop schema
	if ( get_options()&DBO_DROPSCHEMA && query("DROP DATABASE IF EXISTS `%s`", get_schema()) )
	{
		if ( strcmp(get_schema(),"gridlabd")==0 )
			gl_warning("%s uses NEWDB option on the default schema '%s' - this is extremely risky", get_name(), get_schema());
		gl_verbose("schema '%s' dropped ok", get_schema());
	}

	// check schema
	MYSQL_RES *res = mysql_list_dbs(mysql,get_schema());
	if ( mysql_num_rows(res)==0 )
	{
		if ( !(get_options()&DBO_NOCREATE) )
		{
			if ( query("CREATE DATABASE IF NOT EXISTS `%s`", get_schema()) )
				gl_verbose("created schema '%s' ok", get_schema());
		}
		else
			exception("NOCREATE option prevents automatic creation of schema '%s'", get_schema());
	}
	else
		gl_verbose("schema '%s' found ok", get_schema());

	// use schema
	if ( mysql_select_db(mysql,get_schema())!=0 )
		exception("unable to select schema '%s'", get_schema());

	// execute on_init script
	if ( strcmp(get_on_init(),"")!=0 )
	{
		gl_verbose("%s running on_init script '%s'", get_name(), get_on_init());
		int res = run_script(get_on_init());
		if ( res<=0 )
			exception("on_init script '%s' failed at line %d: %s", get_on_init(), -res, get_last_error());
	}
	return 1;
}
Exemplo n.º 21
0
const Schema & get_schema (boost::string_ref str_ver)
{
    if (auto ver = parse_ver (str_ver)) return get_schema (*ver);

    throw std::runtime_error ("Unknown fix version: " + str_ver.to_string ());
}
Exemplo n.º 22
0
void row_t::set_value(const char * col_name, void * ptr) {
	uint64_t id = get_schema()->get_field_id(col_name);
	set_value(id, ptr);
}
Exemplo n.º 23
0
pdal::Schema Reader::fetchSchema(Statement statement, sdo_pc* pc, boost::uint32_t& capacity, std::string ns_override) const
{
    log()->get(logDEBUG) << "Fetching schema from SDO_PC object" << std::endl;

    // Fetch the XML that defines the schema for this point cloud
    std::ostringstream select_schema;
    OCILobLocator* metadata = NULL;
    select_schema
            << "DECLARE" << std::endl
            << "PC_TABLE VARCHAR2(32) := '" << statement->GetString(pc->base_table) << "';" << std::endl
            << "PC_ID NUMBER := " << statement->GetInteger(&(pc->pc_id)) << ";" << std::endl
            << "PC_COLUMN VARCHAR2(32) := '" << statement->GetString(pc->base_column) << "';" << std::endl
            << "BEGIN" << std::endl
            << std::endl
            << "EXECUTE IMMEDIATE" << std::endl
            << " 'SELECT T.'||PC_COLUMN||'.PC_OTHER_ATTRS.getClobVal(), T.'||PC_COLUMN||'.PTN_PARAMS FROM '||pc_table||' T WHERE T.ID='||PC_ID INTO :metadata, :capacity;"
            << std::endl
            << "END;"
            << std::endl;
    Statement get_schema(m_connection->CreateStatement(select_schema.str().c_str()));
    get_schema->BindName(":metadata", &metadata);

    int ptn_params_length = 1024;
    char* ptn_params = (char*) malloc(sizeof(char*) * ptn_params_length);
    ptn_params[ptn_params_length-1] = '\0'; //added trailing null to fix ORA-01480
    get_schema->BindName(":capacity", ptn_params, ptn_params_length);
    get_schema->Execute();

    char* pc_schema = get_schema->ReadCLob(metadata);

    std::string write_schema_file = getOptions().getValueOrDefault<std::string>("xml_schema_dump", std::string(""));
    if (write_schema_file.size() > 0)
    {
        std::ostream* out = FileUtils::createFile(write_schema_file);
        out->write(pc_schema, strlen(pc_schema));
        FileUtils::closeFile(out);
    }


    // Fetch the block capacity from the point cloud object so we
    // can use it later.
    // PTN_PARAMS is like:
    // 'blk_capacity=1000,work_tablespace=my_work_ts'
    int block_capacity = 0;
    boost::char_separator<char> sep_space(" ");
    boost::char_separator<char> sep_equal("=");

    std::string s_cap(ptn_params);
    tokenizer parameters(s_cap, sep_space);
    for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
    {
        tokenizer parameter((*t), sep_equal);

        for (tokenizer::iterator c = parameter.begin(); c != parameter.end(); ++c)
        {
            if (boost::iequals(c->c_str(), "blk_capacity"))
            {
                tokenizer::iterator d = ++c;
                block_capacity = atoi(d->c_str());
            }
        }
    }

    if (block_capacity < 1)
    {
        std::ostringstream oss;
        oss << "Invalid block capacity for point cloud object in Oracle: " << block_capacity;
        throw pdal_error(oss.str());
    }

    capacity = block_capacity;

    std::string pc_schema_xml(pc_schema);
    if (pc_schema)
        CPLFree(pc_schema);

    if (ptn_params)
        free(ptn_params);

    Schema schema = Schema::from_xml(pc_schema_xml);

    schema::index_by_index const& dims = schema.getDimensions().get<schema::index>();

    for (schema::index_by_index::const_iterator iter = dims.begin(); iter != dims.end(); ++iter)
    {
        // For dimensions that do not have namespaces, we'll set the namespace
        // to the namespace of the current stage

        if (iter->getNamespace().size() == 0)
        {
            log()->get(logDEBUG4) << "setting namespace for dimension " << iter->getName() << " to "  << getName() << std::endl;


            Dimension d(*iter);
            if (iter->getUUID().is_nil())
            {
                d.createUUID();
            }

            if (ns_override.size() > 0)
            {
                d.setNamespace(ns_override);
            }
            else
            {
                d.setNamespace(getName());
            }
            schema.setDimension(d);
        }
    }

    return schema;
}
Exemplo n.º 24
0
uint64_t row_t::get_field_cnt() { 
	return get_schema()->field_cnt;
}
Exemplo n.º 25
0
char * row_t::get_value(int id) {
	int pos = get_schema()->get_field_index(id);
	return &data[pos];
}
Exemplo n.º 26
0
char * row_t::get_value(char * col_name) {
	uint64_t pos = get_schema()->get_field_index(col_name);
	return &data[pos];
}
Exemplo n.º 27
0
uint64_t row_t::get_tuple_size() {
	return get_schema()->get_tuple_size();
}
Exemplo n.º 28
0
void row_t::set_value(int id, void * ptr, int size) {
	int pos = get_schema()->get_field_index(id);
	memcpy( &data[pos], ptr, size);
}