Forum: Building VoltDB Applications

Post: Can procedures in voltDB return void?

Can procedures in voltDB return void?
webbean
Sep 4, 2013
Can procedures in voltDB return void?

	
        public void run(String language) throws VoltAbortException {
        }


that is, if i have a procedure which only updates the table and has no SELECT statement,
can this kind of procedures return void like below?


public class Insert extends VoltProcedure {

	public final SQLStmt sql = new SQLStmt(
			"INSERT INTO HELLOWORLD VALUES (?, ?, ?);");

	public void run(String language, String hello, String world)
			throws VoltAbortException {
		voltQueueSQL( sql, hello, world, language );
		voltExecuteSQL();
	}

}
jhugg
Sep 4, 2013
No.

All procedures return an array of VoltTables. We allow you to return a long, a scalar VoltTable or a VoltTable array from a proc. In all cases, these will be converted into an array of VoltTables for the calling client. The long, for example, will be converted into an array of one VoltTable which has a single row and a single column with a long value. You can use the .asScalarLong() convenience method on VoltTable to get at it faster.

So the simplest thing to do is add the word "return" before where you call "voltExecuteSQL()" above. That will return modified tuples to the client (presumably the number 1).
webbean
Sep 4, 2013
Hi, jhugg
Thank you very much.

I am reading the book named "Using VoltDB", there are some warings about the static variables,
i wonder that can i use static variables normally. Is it correct if i add static modifier to the "sql" variable
in the sample above?


public class Insert extends VoltProcedure {

	public static final SQLStmt sql = new SQLStmt(
			"INSERT INTO HELLOWORLD VALUES (?, ?, ?);");

	public VoltTable[] run(String language, String hello, String world)
			throws VoltAbortException {
		voltQueueSQL( sql, hello, world, language );
		return voltExecuteSQL();
	}

}