MySQL Forums
Forum List  »  NDB clusters

Re: NdbApi setValue does not support decimal type?
Posted by: Jacky Huang
Date: June 18, 2012 01:09AM

Hi Bernhard,

1, Additional remarks, I use mysql-cluster-gpl-7.1.21 NDB API and I want to use C++ to write the program, NOT java.

2, I had responded your requestions before - I have read what you reminded, I answer this second time now.

Indeed, I would like to write the value to database. Yeah, the format can be changed by ourselves, but how to stored to the disk ??? This is the key. Please forgive me is a junior, and please GIVE A SAMPLE, I deep fall into this trouble.

2.1.I find the functions of decimal_str2bin and decimal_bin2str in "mysql-cluster-gpl-7.1.21\storage\ndb\src\ndbjtie\mysql\decimal_utils.hpp or cpp"

2.2. DataTypeHandler.cc is not found in mysql-cluster-gpl-7.1.21, but mysql-cluster-gpl-7.2.5.

2.3. What I should do likes 1.1234 -> decimal_str2bin -> decimal_bin2str -> (myOperation->setValue) ???

--------------------------------------------------------------------------------------------------------------------------------------------------


int dth_decode_decimal(const NdbDictionary::Column *col,
char * &str, const void *buf) {
int scale = col->getScale();
int prec = col->getPrecision();
int len = scale + prec + 3;
decimal_bin2str(buf, col->getSizeInBytes(), prec, scale, str, len);
return strlen(str);
}


int dth_encode_decimal(const NdbDictionary::Column *col, size_t len,
const char *str, void *buf) {
MAKE_COPY_BUFFER(64);
int scale = col->getScale();
int prec = col->getPrecision();
int r = decimal_str2bin(str, len, prec, scale, buf, col->getSizeInBytes());
if(r == E_DEC_OK || r == E_DEC_TRUNCATED) {
return len;
}
else {
DEBUG_PRINT("deicmal_str2bin() returns %d", r);
return DTH_NUMERIC_OVERFLOW;
}
}

/*
decimal_str2bin: Convert string directly to on-disk binary format.
str - string to convert
str_len - length of string
prec - precision of column
scale - scale of column
bin - buffer for binary representation
bin_len - length of buffer

NOTES
Added so that NDB API programs can convert directly between the stored
binary format and a string representation without using decimal_t.

RETURN VALUE
E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_OOM
*/
int decimal_str2bin(const char *str, int str_len,
int prec, int scale,
void *bin, int bin_len);


/*
decimal_bin2str(): Convert directly from on-disk binary format to string
bin - value to convert
bin_len - length to convert
prec - precision of column
scale - scale of column
str - buffer for string representation
str_len - length of buffer

NOTES
Added so that NDB API programs can convert directly between the stored
binary format and a string representation without using decimal_t.


RETURN VALUE
E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_BAD_NUM/E_DEC_OOM
*/
int decimal_bin2str(const void *bin, int bin_len,
int prec, int scale,
char *str, int str_len);

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: NdbApi setValue does not support decimal type?
1230
June 18, 2012 01:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.