Пример #1
0
/*
 * Open a connection to an existing kdb+ process.
 *
 * If we just have a host and port we call khp from the kdb+ interface.
 * If we have a host, port, "username:password" we call instead khpu.
 */
SEXP kx_r_open_connection(SEXP whence)
{
	SEXP result;
	int connection, port;
	char *host;
	int length = GET_LENGTH(whence);
	if (length < 2)
		error("Can't connect with so few parameters..");

	port = INTEGER_POINTER (VECTOR_ELT(whence, 1))[0];
	host = (char*) CHARACTER_VALUE(VECTOR_ELT(whence, 0));

	if (2 == length)
		connection = khp(host, port);
	else {
		char *user = (char*) CHARACTER_VALUE(VECTOR_ELT (whence, 2));
		connection = khpu(host, port, user);
	}
        if (!connection)
          error("Could not authenticate");
        else if (connection < 0) {
#ifdef WIN32
          char buf[256];
          FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL);
          error(buf);
#else
	  error(strerror(errno));
#endif
	}
	PROTECT(result = NEW_INTEGER(1));
	INTEGER_POINTER(result)[0] = connection;
	UNPROTECT(1);
	return result;
}
Пример #2
0
int main(int argc,char*argv[])
{
    K flip,result,columnNames,columnData;

    int row,col,nCols,nRows;
	int handle=khpu("localhost",1234,"user:password");
    if(handle<0) exit(1);
	result = k(handle,"`asc",(K)0);
	std::string str = "([]a:til 10;b:reverse til 10;c:10#01010101010b;d:`a)";
	result = k(handle,str.c_str(),(K)0);
    if(!result) printf("Network Error\n"),perror("Network"),exit(1);
    if(result->t==-128) printf("Server Error %s\n",result->s),kclose(handle),exit(1);
//    kclose(handle);
    if(result->t!=99&&result->t!=98) 
	{
		printf("type %d\n",result->t);
		r0(result);
		exit(1);
	}
    flip = ktd(result); // if keyed table, unkey it. ktd decrements ref count of arg.
    // table (flip) is column names!list of columns (data)
    columnNames = kK(flip->k)[0];
    columnData = kK(flip->k)[1];
    nCols = columnNames->n;
    nRows = kK(columnData)[0]->n;
    for(row=0;row<nRows;row++)
    {
        if(0==row)
        {
            for(col=0;col<nCols;col++)
            {   
                if(col>0)printf(",");
                printf("%s",kS(columnNames)[col]);
            }
            printf("\n");
        }
        for(col=0;col<nCols;col++)
        {
            K obj=kK(columnData)[col];

            if(col>0)printf(",");
            switch(obj->t)
            {
                case(1):{printf("%d",kG(obj)[row]);}break;
                case(4):{printf("%d",kG(obj)[row]);}break;
                case(5):{printf("%d",kH(obj)[row]);}break;
                case(6):{printf("%d",kI(obj)[row]);}break;
                case(7):{printf("%lld",kJ(obj)[row]);}break;
                case(8):{printf("%f",kE(obj)[row]);}break;
                case(9):{printf("%f",kF(obj)[row]);}break;
                case(11):{printf("%s",kS(obj)[row]);}break;
                default:{printf("unknown type");}break;
            }
        }
        printf("\n");
    }
    r0(flip);
    return 0;
}
Пример #3
0
Файл: k.c Проект: geocar/qlua
static int wrap_khp(lua_State* L)
{
	S h=luaL_optstring(L,1,"0");
	I p=luaL_optint(L,2,5000);
	S u=luaL_optstring(L,3,0);
	I t=luaL_optint(L,4,-1);
	if(t<0){if(!u)RI(last_connection=khp(h,p));RI(last_connection=khpu(h,p,u));}
	RI(last_connection=khpun(h,p,u,t));
}