package kx; //jar cf c.jar kx/*.class import java.net.*;import java.io.*;import java.sql.*;import java.lang.reflect.Array;import java.text.*; //tick: c c=new c("",5010);Object[]x={"GE",new Double(2.5),new Integer(23)};c.k(".u.upd","trade",x); //Object[]x={new Time(t()),"xx",new Double(93.5),new Integer(300)};for(int i=0;i<1000;++i)c.ks("upsert","trade",x);c.k(""); //Flip t=td(c.k("select sum size by sym from trade"));O(n(t.x));O(n(t.y[0]));O(at(t.y[0],0)); //cols rows data public class c{ /*public static void main(String[]args){try{c c=new c("",5001); // O(c.k("0N!",c.k("0N!1999.01.01D-1"))); //c.k("0N!",NULL('z')); //c.setEncoding("UTF-8");O("Unicode "+c.k("{`$x}","Ranby Björklund AB".toCharArray()));O("Unicode "+c.k("{x}",(String)c.k("{`$x}",(char[])c.k("\"c\"$0x52616e627920426ac3b6726b6c756e64204142")))); c.close();}catch(Exception e){e.printStackTrace();}} */ private static String e="ISO-8859-1";private static PrintStream out=System.out; public static void setEncoding(String e)throws UnsupportedEncodingException{c.e=e;out=new PrintStream(System.out,true,e);} public Socket s;DataInputStream i;OutputStream o;byte[]b,B;int j,J;boolean a,v6; void io(Socket x)throws IOException{s=x;i=new DataInputStream(s.getInputStream());o=s.getOutputStream();}public void close()throws IOException{if(null!=s){s.close();s=null;};if(null!=i){i.close();i=null;}if(null!=o){o.close();o=null;}} public c(ServerSocket s)throws IOException{io(s.accept());i.read(b=new byte[99]);o.write(b,0,1);} //c c=new c(new ServerSocket(5010));while(true)c.w(2,c.k()); public c(String h,int p,String u)throws KException,IOException{B=new byte[2+ns(u)];io(new Socket(h,p));J=0;w(u+"\1");o.write(B);if(1!=i.read(B,0,1)){close();B=new byte[1+ns(u)];io(new Socket(h,p));J=0;w(u);o.write(B);if(1!=i.read(B,0,1)){close();throw new KException("access");}}v6=B[0]==1;} public c(String h,int p)throws KException,IOException{this(h,p,System.getProperty("user.name"));} protected c(){}; public static class Month{public int i;public Month(int x){i=x;}public String toString(){int m=i+24000,y=m/12;return i==ni?"":i2(y/100)+i2(y%100)+"-"+i2(1+m%12);}public boolean equals(final Object o){return(o instanceof Month)?((Month)o).i==i:false;}} public static class Minute{public int i;public Minute(int x){i=x;}public String toString(){return i==ni?"":i2(i/60)+":"+i2(i%60);} public boolean equals(final Object o){return(o instanceof Minute)?((Minute)o).i==i:false;}} public static class Second{public int i;public Second(int x){i=x;}public String toString(){return i==ni?"":new Minute(i/60).toString()+':'+i2(i%60);}public boolean equals(final Object o){return(o instanceof Second)?((Second)o).i==i:false;}} public static class Timespan{public long j;public Timespan(long x){j=x;}public String toString(){return j==nj?"":j+"";} public boolean equals(final Object o){return(o instanceof Timespan)?((Timespan)o).j==j:false;}} public static class Dict{public Object x;public Object y;public Dict(Object X,Object Y){x=X;y=Y;}} public static class Flip{public String[]x;public Object[]y;public Flip(Dict X){x=(String[])X.x;y=(Object[])X.y;}public Object at(String s){return y[find(x,s)];}} public static class KException extends Exception{KException(String s){super(s);}} private void u(){int n=0,r=0,f=0,s=8,p=s;short i=0;j=0;byte[]dst=new byte[ri()];int d=j;int[]aa=new int[256];while(s>8));w((byte)h);} int ri(){int x=rh(),y=rh();return a?x&0xffff|y<<16:x<<16|y&0xffff;} void w(int i){w((short)(i>>16));w((short)i);} long rj(){int x=ri(),y=ri();return a?x&0xffffffffL|(long)y<<32:(long)x<<32|y&0xffffffffL;} void w(long j){w((int)(j>>32));w((int)j);} float re(){return Float.intBitsToFloat(ri());} void w(float e){w(Float.floatToIntBits(e));} double rf(){return Double.longBitsToDouble(rj());} void w(double f){w(Double.doubleToLongBits(f));} Month rm(){return new Month(ri());} void w(Month m){w(m.i);} Minute ru(){return new Minute(ri());} void w(Minute u){w(u.i);} Second rv(){return new Second(ri());} void w(Second v){w(v.i);}Timespan rn(){return new Timespan(rj());} void w(Timespan n){if(!v6)throw new RuntimeException("Timespan not valid pre kdb+2.6");w(n.j);} public java.util.TimeZone tz=java.util.TimeZone.getDefault(); static long k=86400000L*10957,n=1000000000L;long o(long x){return tz.getOffset(x);}long lg(long x){return x+o(x);}long gl(long x){return x-o(x-o(x));} Date rd(){int i=ri();return new Date(i==ni?nj:gl(k+86400000L*i));} void w(Date d){long j=d.getTime();w(j==nj?ni:(int)(lg(j)/86400000-10957));} Time rt(){int i=ri();return new Time(i==ni?nj:gl(i));} void w(Time t){long j=t.getTime();w(j==nj?ni:(int)(lg(j)%86400000));} //Timestamp java.util.Date rz(){double f=rf();return new java.util.Date(Double.isNaN(f)?nj:gl(k+Math.round(8.64e7*f)));} void w(java.util.Date z){long j=z.getTime();w(j==nj?nf:(lg(j)-k)/8.64e7);} Timestamp rp(){long j=rj(),d=j<0?(j+1)/n-1:j/n;Timestamp p=new Timestamp(j==nj?j:gl(k+1000*d));if(j!=nj)p.setNanos((int)(j-n*d));return p;} void w(Timestamp p){long j=p.getTime();if(!v6)throw new RuntimeException("Timestamp not valid pre kdb+2.6");w(j==nj?j:1000000*(lg(j)-k)+p.getNanos()%1000000);} String rs()throws UnsupportedEncodingException{int i=j;for(;b[j++]!=0;);return (i==j-1)?"":new String(b,i,j-1-i,e);}void w(String s)throws UnsupportedEncodingException{int i=0,n=ns(s);byte[]b=s.getBytes(e);for(;i99){if(t==100){rs();return r();}if(t<104)return b[j++]==0&&t==101?null:"func";if(t>105)r();else for(n=ri();i4&&x.equals(NULL[t]);} public static Object at(Object x,int i){return qn(x=Array.get(x,i))?null:x;} public static void set(Object x,int i,Object y){Array.set(x,i,null==y?NULL[t(x)]:y);} static int find(String[]x,String y){int i=0;for(;i0)O(t-u);}static String i2(int i){return new DecimalFormat("00").format(i);} } //2012.03.01 added equals() for Month,Minute,Second,Timespan. null checks in close(). // empty constructor c() and changed w(int,Object) to protected //2012.02.09 close() if connect fails //2012.01.06 read datetime, rz(), was truncating mS rather than rounding //2010.10.06 block sending timestamp/timespan types to versions prior to kdb+2.6 //2010.05.06 optimized rs() for reading null symbols //2010.03.20 changed datetime to java.util.Date as it was incompatible with timestamp //2010.02.01 added unicode support for char vectors and symbol //2010.01.06 fixed 0Np //2009.12.07 removed v6 dependencies //2009.12.02 uncommented at, set and qn //2009.10.29 u - uncompress, connect retry for v<=2.5 //2009.09.23 Timestamp,Timespan,v6 connect //2008.08.14 String(,,,"ISO-8859-1") to avoid mutex //2007.10.18 tz //2007.08.06 kx //2007.04.20 sql.{Date|Time|Timestamp}