00001 #include "clssdf.h"
00002
00003 namespace class_def {
00004
00005 void class_definition::print_singleton_select( std::ostream& os ) const {
00006
00007 std::vector<attribute*>::const_iterator ppa;
00008 long nstr;
00009
00010 os << "int " << _name << "::singleton_select() {" << std::endl << std::endl;
00011
00012 os << " init_static_attributes();" << std::endl << std::endl;
00013
00014 if (_functional_attributes.size()>0) {
00015 os << " EXEC SQL SELECT" << std::endl;
00016
00017
00018 for (std::vector<functional_attribute>::const_iterator pa=_functional_attributes.begin();;)
00019 {
00020 os << " " << pa->get_name();
00021 pa++;
00022 if (pa==_functional_attributes.end()) {
00023 os << std::endl;
00024 break;
00025 } else {
00026 os << "," << std::endl;
00027 }
00028 }
00029
00030 os << " INTO" << std::endl;
00031 for (std::vector<functional_attribute>::const_iterator pa=_functional_attributes.begin();;) {
00032 os << " :" << pa->get_Name();
00033 pa++;
00034 if (pa==_functional_attributes.end()) {
00035 os << std::endl;
00036 break;
00037 } else {
00038 os << "," << std::endl;
00039 }
00040 }
00041 os << " FROM " << _name << std::endl;
00042 os << " WHERE" << std::endl;
00043 for (std::vector<key_attribute>::const_iterator pa=_key_attributes.begin();;)
00044 {
00045 os << " " << pa->get_name() << "=:" << pa->get_Name();
00046 pa++;
00047 if (pa==_key_attributes.end()) {
00048 os << ";" << std::endl;
00049 break;
00050 } else {
00051 os << " AND" << std::endl;
00052 }
00053 }
00054 os << std::endl;
00055
00056 nstr = 0;
00057 for (std::vector<functional_attribute>::const_iterator pa=_functional_attributes.begin();
00058 pa!=_functional_attributes.end();
00059 pa++)
00060 {
00061 if (pa->get_type()=="std::string") {
00062 os << " " << pa->storage_format_of_name() << " = " << "mystring::string_desc_2_string( ";
00063 os << pa->get_Name() << ", sizeof( " << pa->get_Name() << "));" << std::endl;
00064 nstr++;
00065 }
00066 }
00067 if (nstr) {
00068 os << std::endl;
00069 }
00070
00071 os << " _sql_err();" << std::endl << std::endl;
00072
00073 os << " init(" << std::endl;
00074 for (ppa=_defined_attributes.begin();;) {
00075 if ((*ppa)->get_type()=="std::string") {
00076 os << " " << (*ppa)->storage_format_of_name();
00077 } else {
00078 os << " " << (*ppa)->get_Name();
00079 }
00080 ppa++;
00081 if (ppa==_defined_attributes.end()) {
00082 os << ");" << std::endl << std::endl;
00083 break;
00084 } else {
00085 os << "," << std::endl;
00086 }
00087 }
00088
00089 os << " return 1;" << std::endl;
00090 } else {
00091 os << " return exists();" << std::endl;
00092 }
00093 os << "}" << std::endl << std::endl;
00094 }
00095 }
00096