コード例 #1
0
ファイル: ref.cpp プロジェクト: att/uwin
void reference::set_date(string &d)
{
  if (d.length() == 0)
    delete_field('D');
  else
    insert_field('D', d);
}
コード例 #2
0
ファイル: main.c プロジェクト: yorickdewid/dbtree
int main(int argc, char *argv[]){
	char buffer[64];
	char *c;

#if DEBUG
	printf("[DEBUG MODE]\n");
	printf("Compile: %s %s\n", __DATE__, __TIME__);
#endif

	printf("Version: %d.%d.%d\n", VER_REL, VER_MAJOR, VER_MINOR);
	printf("Database> ");
	dbfile_t *mdb = open_dbfile(get_input(buffer, 32, TRUE));
	commit_db(mdb);

	for(;;){
		printf("valca> ");

		c = get_input(buffer, 64, TRUE);
		if(!strcmp("quit", c)||!strcmp("exit", c)||!strcmp("\\q", c)){
			break;
		}
		if(!strcmp("help", c)){
			printf("COMMANDS:\n");
			printf("COMMIT        Commit file to disk\n");
			printf("COUNT         Show row count\n");
			printf("TRUNCATE      Delete all keys\n");
			printf("UPDATE        Update key value\n");
			printf("INSERT        Insert key\n");
			printf("DELETE \\\n");
			printf("  COLUMN      Delete column\n");
			printf("  ROW         Delete row\n");
			printf("ALTER \\\n");
			printf("  NAME        Change column name\n");
			printf("  LEFT        Shift column left\n");
			printf("  RIGHT       Shift column right\n");
			printf("SELECT        Select value from\n");
			printf("ADD \\\n");
			printf("  COLUMN      Add column\n");
			printf("SHOW \\\n");
			printf("  COLUMNS     Show all columns\n");
			printf("  TREE        Show storage tree\n");
			printf("  STATUS      Show database info\n");
			printf("  TABLE       Show dataset as table\n");
			printf("FREE \\\n");
			printf("  COLUMNS     Columns freelist\n");
			printf("  NODE        Node freelist\n");
			printf("  DATAFIELDS  Payload freelist\n");
			printf("EXIT          Quit the shell\n");
		}
		if(!strcmp("commit", c)){
			commit_db(mdb);
		}
		if(!strcmp("count", c)){
			printf("Total rows: %d\n", mdb->k_cnt);
		}
		if(!strcmp("truncate", c)){
			truncate_root(mdb);
		}
		if(!strcmp("update", c)){
			char tmp[32];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			char tmpcolname[32];
			printf(">column: ");
			c = get_input(tmpcolname, 32, FALSE);
			int idx = get_column_idx(mdb, tmpcolname);
			printf(">value: ");
			c = get_input(tmp, 32, FALSE);
			change(mdb, key, (void*)tmp, idx);
		}
		if(!strcmp("insert", c)){
			if(!mdb->c_cnt){
				printf("Cannot insert without column\n");
			}else{
				char tmp[32];
				printf(">psid[%d]: ", mdb->seq_cnt);
				c = get_input(tmp, 32, FALSE);
				int key;
				if(!strlen(tmp)){
					key = mdb->seq_cnt++;
				}else{
					key = atoi(tmp);
				}
				column_t col;
				read_column(mdb, mdb->data.c_root, &col);
				printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
				c = get_input(tmp, 32, FALSE);
				if(get_datatype(col.d_type).size == -1) tmp[col.maxsize] = '\0';
				if(col.usign) printf("<> %d\n", atoi(tmp));
					//if(atoi())
				if(insert_key(mdb, key, (void*)tmp) == SUCCESS){
					result_t rs = search_key(mdb, key);
					if(rs.rstat == SUCCESS){
						char tmp[32];
						int i = 1;
						while(col.c_next != EMPTY){
							read_column(mdb, col.c_next, &col);
							printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
							c = get_input(tmp, 32, FALSE);
							add_field(mdb, rs.fpos, rs.idx, (void*)tmp, i);
							i++;
						}
					}
				}
			}
		}
		if(!strcmp("delete", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				delete_column(mdb, idx);
			}
			if(!strcmp("row", c)){
				char tmp[32];
				printf(">psid: ");
				c = get_input(tmp, 32, FALSE);
				int key = atoi(tmp);
				result_t rs = search_key(mdb, key);
				if(rs.rstat == SUCCESS){
					int i;
					for(i=mdb->c_cnt; i>1; i--){
						delete_field(mdb, rs.fpos, rs.idx, (i-1));
					}
					delete_key(mdb, key);
				}
			}
		}
		if(!strcmp("alter", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("name", c)){
				printf(">column: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				printf(">new name: ");
				c = get_input(tmpcolname, 32, FALSE);
				rename_column(mdb, tmpcolname, idx);
			}
			if(!strcmp("left", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_left(mdb, idx);
			}
			if(!strcmp("right", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_right(mdb, idx);
			}
		}
		if(!strcmp("select", c)){
			printf(">");
			char tmp[16];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			result_t rs = search_key(mdb, key);
			if(rs.rstat == SUCCESS){
				found(mdb, rs.fpos, rs.idx);
			}
		}
		if(!strcmp("add", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char colname[32];
				DTYPE type;
				int size;
				bool usign = FALSE;
				int idx;
				printf(">name: ");
				c = get_input(colname, 32, FALSE);
				printf(">type: ");
				char tmptype[32];
				c = get_input(tmptype, 32, FALSE);
				type = get_datatype_idx(tmptype);
				if(type == EMPTY){
					printf("Unkown datatype\n");
					continue;
				}
				size = get_datatype(type).size;
				if(size == EMPTY){
					printf(">size: ");
					char tmpsize[16];
					c = get_input(tmpsize, 16, FALSE);
					size = atoi(tmpsize);
				}
				if(get_datatype(type).signness){
					printf(">unsigned: ");
					char tmpsign[4];
					c = get_input(tmpsign, 4, FALSE);
					if(!strcmp("y", tmpsign)){
						usign = TRUE;
					}
				}
				printf(">before: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				idx = get_column_idx(mdb, tmpcolname);
				add_column(mdb, colname, size, type, usign, idx);
			}
		}
		if(!strcmp("show", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_root, 0);
			}
			if(!strcmp("tree", c)){
				print_tree(mdb, mdb->data.n_root, 0);
			}
			if(!strcmp("status", c)){
				print_status(mdb);
			}
			if(!strcmp("table", c)){
				print_table(mdb);
			}
		}
		if(!strcmp("free", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_free, 0);
			}
			if(!strcmp("node", c)){
				print_tree(mdb, mdb->data.n_free, 0);
			}
			if(!strcmp("datafields", c)){
				print_datafield(mdb, mdb->data.d_free);
			}
		}
	}

	commit_db(mdb);
	close_dbfile(mdb->vfp);
	close_db(mdb);

	return 0;
}
コード例 #3
0
ファイル: fieldWindow.cpp プロジェクト: iyer-arvind/gmsh
static void field_delete_cb(Fl_Widget *w, void *data)
{
  Field *f = (Field*)FlGui::instance()->fields->editor_group->user_data();
  delete_field(f->id, GModel::current()->getFileName());
  FlGui::instance()->fields->editField(NULL);
}