Example #1
0
/*
** define schema for parser
** @params parser
** @return void
*/
static void	parser_schema(t_parser *parser)
{
  parser->schema[0] = new_schema(SEMICOLON_TOKEN, semicolon_generate, NULL);
  parser->schema[1] = new_schema(AND_TOKEN, and_generate, NULL);
  parser->schema[2] = new_schema(OR_TOKEN, or_generate, NULL);
  parser->schema[3] = new_schema(PIPE_TOKEN, pipe_generate, NULL);
  parser->schema[4] = new_schema(DOUBLE_RIGHT_TOKEN,
				 double_right_generate, NULL);
  parser->schema[5] = new_schema(SIMPLE_RIGHT_TOKEN,
				 simple_right_generate, NULL);
  parser->schema[6] = new_schema(DOUBLE_LEFT_TOKEN, double_left_generate, NULL);
  parser->schema[7] = new_schema(SIMPLE_LEFT_TOKEN, simple_left_generate, NULL);
  parser->schema[8] = new_schema("", exec_generate, exec_find_in);
}
Example #2
0
static schema_p copy_schema ( schema_p s, const char *dest_name )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = s->first;
  for ( ; f != NULL; f = f->next)
    add_field (dest, copy_field (f));
  return dest;
}
Example #3
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;
	}
    }
}
Example #4
0
KexiDB::SchemaData* KexiView::copyData(const KexiDB::SchemaData& sdata,
                                        KexiView::StoreNewDataOptions options,
                                        bool &cancel)
{
    Q_UNUSED(options)
    Q_UNUSED(cancel)
    QScopedPointer<KexiDB::SchemaData> new_schema(new KexiDB::SchemaData);
    *new_schema = sdata;

    KexiDB::Connection *conn = KexiMainWindowIface::global()->project()->dbConnection();
    if (!conn->storeObjectSchemaData(*new_schema.data(), true)
        || !conn->copyDataBlock(d->window->id(), new_schema->id())
        || !KexiMainWindowIface::global()->project()->copyUserDataBlock(d->window->id(), new_schema->id())
       )
    {
        return 0;
    }
    d->newlyAssignedID = new_schema->id();
    return new_schema.take();
}
Example #5
0
static schema_p make_sub_schema ( schema_p s, const char *dest_name,
				  int num_fields, char *fields[] )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = NULL;
  int i = 0;
  for ( i= 0; i < num_fields; i++)
    {
      f = get_field ( s, fields[i] );
      if ( f != NULL)
	add_field (dest, copy_field (f));
      else
	{
	  put_msg (ERROR, "\"%s\" has no \"%s\" field\n",
		   s->name, fields[i]);
	  remove_schema (dest);
	  return NULL;
	}
    }
  return dest;
}
Example #6
0
static void read_tbl_descs ()
{
  
  FILE *fp = fopen (tables_desc_file, "r");
  if ( fp == NULL ) return;
  char name[30] = "";
  schema_p sch;
  field_desc_p fld;
  int num_flds = 0, fld_type, fld_len;
  while ( !feof(fp) )
    {
      if ( fscanf ( fp, "%s %d\n", name, &num_flds ) < 2 )
	{
	  fclose (fp);
	  return;
	}
      sch = new_schema ( name );
      int i;
      for (i = 0; i < num_flds; i++ )
	{
	  fscanf ( fp, "%s %d %d", name, &(fld_type), &(fld_len) );
	  switch (fld_type) {
	  case INT_TYPE:
	    fld = new_int_field ( name );
	    break;
	  case STR_TYPE:
	    fld = new_str_field ( name, fld_len );
	    break;
	  }
	  fscanf (fp, "%d\n", &(fld->offset));
	  add_field ( sch, fld );
	}
      fscanf ( fp, "%d\n",  &(sch->tbl->num_records)  );
    }
  db_tables = sch->tbl;
  fclose (fp);
}