ExtRegExp.cpp File Reference

Go to the source code of this file.

Classes

class  ExtRegExpContext

Functions

void strLikeEscapeA (boost::scoped_ptr< ExtendedInstructionContext > &context, RegisterRef< bool > *result, RegisterRef< char * > *matchValue, RegisterRef< char * > *pattern, RegisterRef< char * > *escape)
void strLikeA (boost::scoped_ptr< ExtendedInstructionContext > &context, RegisterRef< bool > *result, RegisterRef< char * > *matchValue, RegisterRef< char * > *pattern)
void strSimilarEscapeA (boost::scoped_ptr< ExtendedInstructionContext > &context, RegisterRef< bool > *result, RegisterRef< char * > *matchValue, RegisterRef< char * > *pattern, RegisterRef< char * > *escape)
void strSimilarA (boost::scoped_ptr< ExtendedInstructionContext > &context, RegisterRef< bool > *result, RegisterRef< char * > *matchValue, RegisterRef< char * > *pattern)
void ExtRegExpRegister (ExtendedInstructionTable *eit)


Function Documentation

void ExtRegExpRegister ( ExtendedInstructionTable eit  ) 

Definition at line 180 of file ExtRegExp.cpp.

References ExtendedInstructionTable::add(), STANDARD_TYPE_BOOL, STANDARD_TYPE_CHAR, STANDARD_TYPE_VARCHAR, strLikeA(), strLikeEscapeA(), strSimilarA(), and strSimilarEscapeA().

Referenced by CalcInit::instance().

00181 {
00182     assert(eit != NULL);
00183 
00184     // JK 2004/5/27: Are all of these combinations really needed?
00185     int i;
00186     for (i = 0; i < 8; i++) {
00187         vector<StandardTypeDescriptorOrdinal> params;
00188 
00189         params.push_back(STANDARD_TYPE_BOOL);
00190 
00191         if (i & 0x01) {
00192             params.push_back(STANDARD_TYPE_CHAR);
00193         } else {
00194             params.push_back(STANDARD_TYPE_VARCHAR);
00195         }
00196         if (i & 0x02) {
00197             params.push_back(STANDARD_TYPE_CHAR);
00198         } else {
00199             params.push_back(STANDARD_TYPE_VARCHAR);
00200         }
00201 
00202         eit->add(
00203             "strLikeA3", params,
00204             (ExtendedInstruction3Context<bool, char*, char*>*) NULL,
00205             &strLikeA);
00206         eit->add(
00207             "strSimilarA3", params,
00208             (ExtendedInstruction3Context<bool, char*, char*>*) NULL,
00209             &strSimilarA);
00210 
00211         // tack on escape parameter
00212         if (i & 0x04) {
00213             params.push_back(STANDARD_TYPE_CHAR);
00214         } else {
00215             params.push_back(STANDARD_TYPE_VARCHAR);
00216         }
00217 
00218         eit->add(
00219             "strLikeA4", params,
00220             (ExtendedInstruction4Context<bool, char*, char*, char*>*) NULL,
00221             &strLikeEscapeA);
00222         eit->add(
00223             "strSimilarA4", params,
00224             (ExtendedInstruction4Context<bool, char*, char*, char*>*) NULL,
00225             &strSimilarEscapeA);
00226     }
00227 }

void strLikeA ( boost::scoped_ptr< ExtendedInstructionContext > &  context,
RegisterRef< bool > *  result,
RegisterRef< char * > *  matchValue,
RegisterRef< char * > *  pattern 
)

Definition at line 104 of file ExtRegExp.cpp.

References strLikeEscapeA().

Referenced by ExtRegExpRegister().

00109 {
00110     strLikeEscapeA(context, result, matchValue, pattern, 0);
00111 }

void strLikeEscapeA ( boost::scoped_ptr< ExtendedInstructionContext > &  context,
RegisterRef< bool > *  result,
RegisterRef< char * > *  matchValue,
RegisterRef< char * > *  pattern,
RegisterRef< char * > *  escape 
)

Definition at line 49 of file ExtRegExp.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::length(), ExtRegExpContext::pattern, RegisterRef< TMPLT >::pointer(), ExtRegExpContext::regex, RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtRegExpRegister(), and strLikeA().

00055 {
00056     assert(StandardTypeDescriptor::isTextArray(matchValue->type()));
00057     assert(StandardTypeDescriptor::isTextArray(pattern->type()));
00058 
00059     // SQL99 Part 2 Section 8.5 General Rule 3.a, cases i & ii
00060     if (matchValue->isNull() ||
00061         pattern->isNull() ||
00062         (escape ? escape->isNull() : false)) {
00063         result->toNull();
00064         result->length(0);
00065     } else {
00066         boost::regex* regexP;
00067         string* patP;
00068         ExtRegExpContext* ctxP;
00069 
00070         ctxP = static_cast<ExtRegExpContext*>(context.get());
00071         if (!ctxP) {
00072             string pat;
00073             SqlLikePrep<1,1>(
00074                 pattern->pointer(),
00075                 pattern->length(),
00076                 (escape ? escape->pointer() : 0),
00077                 (escape ? escape->length() : 0),
00078                 pat);
00079             try {
00080                 boost::regex regex(pat);
00081                 context.reset(new ExtRegExpContext(regex, pat));
00082             } catch (boost::bad_expression badexp) {
00083                 // SQL99 Part 2 Section 8.5 General Rule 3.b.i2 *seems* like
00084                 // best fit here.
00085                 // Data Exception - Invalid Escape Sequence
00086                 throw "22025";
00087             }
00088             // get context anew
00089             ctxP = static_cast<ExtRegExpContext*>(context.get());
00090         }
00091         regexP = &(ctxP->regex);
00092         patP = &(ctxP->pattern);
00093 
00094         result->value(
00095             SqlRegExp<1,1>(
00096                 matchValue->pointer(),
00097                 matchValue->length(),
00098                 pattern->length(),
00099                 *regexP));
00100     }
00101 }

void strSimilarA ( boost::scoped_ptr< ExtendedInstructionContext > &  context,
RegisterRef< bool > *  result,
RegisterRef< char * > *  matchValue,
RegisterRef< char * > *  pattern 
)

Definition at line 170 of file ExtRegExp.cpp.

References strSimilarEscapeA().

Referenced by ExtRegExpRegister().

00175 {
00176     strSimilarEscapeA(context, result, matchValue, pattern, 0);
00177 }

void strSimilarEscapeA ( boost::scoped_ptr< ExtendedInstructionContext > &  context,
RegisterRef< bool > *  result,
RegisterRef< char * > *  matchValue,
RegisterRef< char * > *  pattern,
RegisterRef< char * > *  escape 
)

Definition at line 116 of file ExtRegExp.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::length(), ExtRegExpContext::pattern, RegisterRef< TMPLT >::pointer(), ExtRegExpContext::regex, RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtRegExpRegister(), and strSimilarA().

00122 {
00123     assert(StandardTypeDescriptor::isTextArray(matchValue->type()));
00124     assert(StandardTypeDescriptor::isTextArray(pattern->type()));
00125 
00126     // SQL2003 Part 2 Section 8.5 General Rule 4.a,b
00127     if (matchValue->isNull() ||
00128         pattern->isNull() ||
00129         (escape ? escape->isNull() : false)) {
00130         result->toNull();
00131         result->length(0);
00132     } else {
00133         boost::regex* regexP;
00134         string* patP;
00135         ExtRegExpContext* ctxP;
00136 
00137         ctxP = static_cast<ExtRegExpContext*>(context.get());
00138         if (!ctxP) {
00139             string pat;
00140             SqlSimilarPrep<1,1>(
00141                 pattern->pointer(),
00142                 pattern->length(),
00143                 (escape ? escape->pointer() : 0),
00144                 (escape ? escape->length() : 0),
00145                 pat);
00146             try {
00147                 boost::regex regex(pat);
00148                 context.reset(new ExtRegExpContext(regex, pat));
00149             } catch (boost::bad_expression badexp) {
00150                 // SQL2003 Part 2 Section 8.6 General Rule 2
00151                 // Data Exception - Invalid Regular Expression
00152                 throw "2201B";
00153             }
00154             // get context anew
00155             ctxP = static_cast<ExtRegExpContext*>(context.get());
00156         }
00157         regexP = &(ctxP->regex);
00158         patP = &(ctxP->pattern);
00159 
00160         result->value(
00161             SqlRegExp<1,1>(
00162                 matchValue->pointer(),
00163                 matchValue->length(),
00164                 pattern->length(),
00165                 *regexP));
00166     }
00167 }


Generated on Mon Jun 22 04:00:22 2009 for Fennel by  doxygen 1.5.1