Ejemplo n.º 1
0
str
sql_update_var(mvc *m, char *name, char *sval, lng sgn)
{
	if (strcmp(name, "debug") == 0) {
		assert((lng) GDK_int_min <= sgn && sgn <= (lng) GDK_int_max);
		m->debug = (int) sgn;
	} else if (strcmp(name, "current_schema") == 0) {
		if (!mvc_set_schema(m, sval)) {
			return sql_message( "Schema (%s) missing\n", sval);
		}
	} else if (strcmp(name, "current_role") == 0) {
		if (!mvc_set_role(m, sval)) {
			return sql_message( "Role (%s) missing\n", sval);
		}
	} else if (strcmp(name, "current_timezone") == 0) {
		assert((lng) GDK_int_min <= sgn && sgn <= (lng) GDK_int_max);
		m->timezone = (int) sgn;
	} else if (strcmp(name, "cache") == 0) {
		assert((lng) GDK_int_min <= sgn && sgn <= (lng) GDK_int_max);
		m->cache = (int) sgn;
	} else if (strcmp(name, "history") == 0) {
		assert((lng) GDK_int_min <= sgn && sgn <= (lng) GDK_int_max);
		m->history = (sgn != 0);
	} 
	return NULL;
}
Ejemplo n.º 2
0
str
monet5_user_set_def_schema(mvc *m, oid user)
{
	oid rid;
	sqlid schema_id;
	sql_schema *sys = NULL;
	sql_table *user_info = NULL;
	sql_column *users_name = NULL;
	sql_column *users_schema = NULL;
	sql_table *schemas = NULL;
	sql_column *schemas_name = NULL;
	sql_column *schemas_id = NULL;
	sql_table *auths = NULL;
	sql_column *auths_name = NULL;

	void *p = 0;

	str schema = NULL;
	str username = NULL;

	if (m->debug &1)
		fprintf(stderr, "monet5_user_set_def_schema " OIDFMT "\n", user);

	mvc_trans(m);

	sys = find_sql_schema(m->session->tr, "sys");
	user_info = find_sql_table(sys, "db_user_info");
	users_name = find_sql_column(user_info, "name");
	users_schema = find_sql_column(user_info, "default_schema");

	rid = table_funcs.column_find_row(m->session->tr, users_name, username, NULL);
	if (!is_oid_nil(rid))
		p = table_funcs.column_find_value(m->session->tr, users_schema, rid);

	assert(p);
	schema_id = *(sqlid *) p;
	_DELETE(p);

	schemas = find_sql_table(sys, "schemas");
	schemas_name = find_sql_column(schemas, "name");
	schemas_id = find_sql_column(schemas, "id");
	auths = find_sql_table(sys, "auths");
	auths_name = find_sql_column(auths, "name");

	rid = table_funcs.column_find_row(m->session->tr, schemas_id, &schema_id, NULL);
	if (!is_oid_nil(rid))
		schema = table_funcs.column_find_value(m->session->tr, schemas_name, rid);

	/* only set schema if user is found */
	rid = table_funcs.column_find_row(m->session->tr, auths_name, username, NULL);
	if (!is_oid_nil(rid)) {
		sql_column *auths_id = find_sql_column(auths, "id");
		int id;
		p = table_funcs.column_find_value(m->session->tr, auths_id, rid);
		id = *(int *) p;
		_DELETE(p);

		m->user_id = m->role_id = id;
	} else {
		schema = NULL;
	}

	if (!schema || !mvc_set_schema(m, schema)) {
		if (m->session->active)
			mvc_rollback(m, 0, NULL);
		return NULL;
	}
	/* reset the user and schema names */
	if(!stack_set_string(m, "current_schema", schema) ||
		!stack_set_string(m, "current_user", username) ||
		!stack_set_string(m, "current_role", username)) {
		schema = NULL;
	}
	GDKfree(username);
	mvc_rollback(m, 0, NULL);
	return schema;
}