-
Notifications
You must be signed in to change notification settings - Fork 0
WorkLog
Add an example of mapping from a resultset to a haskell record type. I think it's easier than by using template haskell. See example
Add the parser which understand criteria, projection, order. See example
I have finally closed the issue #7. I made hhe issue open about a week ago, but I came across the problem since when I started coding. Now my next challenge is to coding TLS connection.
I made a presentation of the library.
Learning parser. I am reading ExprParser.java. This page is useful
Hare are methods to generate Expr.
parse orExpr parseLeftAssocBinaryOpExpr OR OROR andExpr parseLeftAssocBinaryOpExpr AND ANDAND ilriExpr IS, IN, LIKE, BETWEEN, REGEXP, NOT compExpr parseLeftAssocBinaryOpExpr GE, GT, LE, LT, EQ, NE bitExpr parseLeftAssocBinaryOpExpr BITAND, BITOR, BITXOR shiftExpr parseLeftAssocBinaryOpExpr LSHIFT, RSHIFT addSubExpr parseLeftAssocBinaryOpExpr PLUS, MINUS mulDivExpr parseLeftAssocBinaryOpExpr STAR, SLASH, MOD addSubIntervalExpr PLUS MINUS INTERVAL atomicExpr EROTEME , COLON , LPAREN , LCURLY , LSQBRACKET , CAST , PLUS , MINUS , NOT , NEG , BANG , LSTRING , NULL , LNUM_INT , LNUM_DOUBLE , TRUE , FALSE , DOLLAR , STAR , IDENT parenExprList ( , .. , .. ) used by IN, FUNCTION_CALL
parseLeftAssocBinaryOpExpr l = innerParse while (check BinaryOperator) r = inserParse l = BO l r
ex:
1 + 2 + 3 -> + (+ 1 2) 3 1 + 2 + 3 + 4 -> + (+ (+ 1 2) 3) 4
An experimental Code
package com.company;
import com.mysql.cj.xdevapi.ExprParser;
public class MyParser01 {
public static void main(String[] args){
System.out.println(new ExprParser(expr06).parse());
}
static String expr01 = "1 + 10 ";
static String expr02 = "CASE WHEN 1>0 THEN 'true' ELSE 'false' END";// com.mysql.cj.core.exceptions.WrongArgumentException: Only 1 tokens consumed, out of 10
static String expr03 = "max (capital)";
static String expr04 = "max (distinct capital)"; // com.mysql.cj.core.exceptions.WrongArgumentException: Expected token type RPAREN at token pos 3
static String expr05 = "1 + 2 + 3";
static String expr06 = "1 + 2 + 3 + 4";
}
type: OPERATOR
operator {
name: "+"
param {
type: OPERATOR
operator {
name: "+"
param {
type: OPERATOR
operator {
name: "+"
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 1
}
}
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 2
}
}
}
}
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 3
}
}
}
}
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 4
}
}
}
Now proxy working! 🎉
Need to refactor code.
I've fallen into an error as follows:
*** Exception: src/PPrint01.hs:(89,1)-(98,131): Non-exhaustive patterns in function myFunc
Haskell is a strongly typed language, so I never thought I got such an error. I was wondering hours. The reason is very simple. I just forgot handling empty list.
buzz :: [Char] -> Bool
buzz (x:xs) = x == 'a'
> buzz "ab"
True
> buzz "xb"
False
> buzz ""
*** Exception: src/PPrint01.hs:113:1-22: Non-exhaustive patterns in function buzz
Need to add.
buzz [] = False
I am still a beginner. 😢
I'm working on a proxy facility for the library and trying to implement logging for messages. I use Text.Pretty.Simple package, which is fine. But the output of a message is a little bit noisy, because Nothing fields are displayed. For example
Right
( PCS
( CapabilitiesSet
{ capabilities = Capabilities
{ capabilities = fromList
[ Capability
{ name = "client.pwd_expire_ok"
, value = Any
{ type' = SCALAR
, scalar = Just
( Scalar
{ type' = V_BOOL
, v_signed_int = Nothing -- (*)
, v_unsigned_int = Nothing -- (*)
, v_octets = Nothing -- (*)
, v_double = Nothing -- (*)
, v_float = Nothing -- (*)
, v_bool = Just True -- (##)
, v_string = Nothing -- (*)
}
)
, obj = Nothing
, array = Nothing
}
}
]
}
}
)
)
You notice the Scalar record above has only a boolean value (##), but other values (*) are printed. So I am trying to remove Nothing values.
Writing client library for a database requires much knowledge, not only MySQL but also other areas. I noticed that I don't know network programing well. So now I am reading TCP/IP Sockets in C: Practical Guide for Programmers (The Practical Guides) (Yes I am reading the Japanese translated Version. 😀 ). Though the book published about 15 years ago, it's not outdated. I haven't finished yet, but I think it explains TCP/IP programming short and concise.