Example #1
0
func (this *Unset) ExecCommand(args []string) (int, string) {
	/* Command to Unset the value of the given parameter.
	 */

	if len(args) > this.MaxArgs() {
		return errors.TOO_MANY_ARGS, ""

	} else if len(args) < this.MinArgs() {
		return errors.TOO_FEW_ARGS, ""

	} else {
		//Check what kind of parameter needs to be Unset.
		// For query parameters
		if strings.HasPrefix(args[0], "-$") {
			// For Named Parameters
			vble := args[0]
			vble = vble[2:]

			err_code, err_str := PopValue_Helper(true, NamedParam, vble)
			if err_code != 0 {
				return err_code, err_str
			}
			go_n1ql.UnsetQueryParams(vble)

		} else if strings.HasPrefix(args[0], "-") {
			// For query parameters
			vble := args[0]
			vble = vble[1:]

			err_code, err_str := PopValue_Helper(true, QueryParam, vble)
			if err_code != 0 {
				return err_code, err_str
			}
			go_n1ql.UnsetQueryParams(vble)

		} else if strings.HasPrefix(args[0], "$") {
			// For User defined session variables
			vble := args[0]
			vble = vble[1:]

			err_code, err_str := PopValue_Helper(true, UserDefSV, vble)
			if err_code != 0 {
				return err_code, err_str
			}

		} else {
			// For Predefined session variables
			vble := args[0]

			err_code, err_str := PopValue_Helper(true, PreDefSV, vble)
			if err_code != 0 {
				return err_code, err_str
			}
		}
	}
	return 0, ""
}
Example #2
0
/* Pop the top value of the parameter stack.
   This is used by the \POP command with no arguments.
*/
func Popparam_Helper(param map[string]*Stack, isrestp bool, isnamep bool) (int, string) {
	for name, val := range param {
		_, err_code, err_str := val.Pop()

		if isrestp == true && val.Len() == 0 {
			delete(param, name)
			go_n1ql.UnsetQueryParams(name)
		}

		if err_code != 0 {
			return err_code, err_str
		}

		if isrestp == true && val.Len() != 0 {
			if isnamep == true {
				name = "$" + name
			}
			err_code, err_str = setNewParamPop(name, val)
			if err_code != 0 {
				return err_code, err_str
			}
		}
	}
	return 0, ""
}
Example #3
0
func (this *Pop) ExecCommand(args []string) (int, string) {

	if len(args) > this.MaxArgs() {
		return errors.TOO_MANY_ARGS, ""

	} else if len(args) < this.MinArgs() {
		return errors.TOO_FEW_ARGS, ""

	} else if len(args) == 0 {
		/* For \Pop with no input arguments, Pop the top value
		on the stack for every variable. Dont return errors in
		this case as any one of these stacks can be empty.
		*/

		//Named Parameters
		Popparam_Helper(NamedParam, true, true)

		//Query Parameters
		Popparam_Helper(QueryParam, true, false)

		//User Defined Session Variables
		Popparam_Helper(UserDefSV, false, false)

		//Should not pop predefined variables unless
		//they are expicitely specified as an arg to POP.
		//Popparam_Helper(PreDefSV, false)

	} else {
		//Check what kind of parameter needs to be popped

		if strings.HasPrefix(args[0], "-$") {
			// For Named Parameters
			vble := args[0]
			vble = vble[2:]

			err_code, err_string := PopValue_Helper(false, NamedParam, vble)
			if err_code != 0 {
				return err_code, err_string
			}

			st_val, ok := NamedParam[vble]

			if ok {
				if NamedParam[vble].Len() == 0 {
					go_n1ql.UnsetQueryParams(vble)
				} else {
					name := "$" + vble
					err_code, err_str := setNewParamPop(name, st_val)
					if err_code != 0 {
						return err_code, err_str
					}
				}

			} else {
				go_n1ql.UnsetQueryParams(vble)
			}

		} else if strings.HasPrefix(args[0], "-") {
			// For query parameters
			vble := args[0]
			vble = vble[1:]

			err_code, err_string := PopValue_Helper(false, QueryParam, vble)
			if err_code != 0 {
				return err_code, err_string
			}

			st_val, ok := QueryParam[vble]

			if ok {
				if QueryParam[vble].Len() == 0 {
					go_n1ql.UnsetQueryParams(vble)
				} else {
					err_code, err_str := setNewParamPop(vble, st_val)
					if err_code != 0 {
						return err_code, err_str
					}
				}

			} else {
				go_n1ql.UnsetQueryParams(vble)
			}

		} else if strings.HasPrefix(args[0], "$") {
			// For User defined session variables
			vble := args[0]
			vble = vble[1:]

			err_code, err_string := PopValue_Helper(false, UserDefSV, vble)
			if err_code != 0 {
				return err_code, err_string
			}

		} else {
			// For Predefined session variables
			vble := args[0]

			err_code, err_string := PopValue_Helper(false, PreDefSV, vble)
			if err_code != 0 {
				return err_code, err_string
			}
		}
	}
	return 0, ""
}