예제 #1
0
파일: Room.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Room room)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "room_id": room._roomID = reader.GetInt32(i);
                                      break;
                    case "branch_id": room._branchID = reader.GetInt32(i);
                                      break;
                    case "name": room._name = reader.GetString(i);
                                      break;
                    case "seat_no": room._seatNo = reader.GetInt32(i);
                                      break;
                    case "img": room._img = reader.GetString(i);
                                      break;
                    case "description": room._description = reader.GetString(i);
                                      break;

                    // helper info
                    case "branch_name": room._branchName = reader.GetString(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
예제 #2
0
파일: AppUser.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, AppUser user)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);
                // Map to DB field. Need to change if db changed
                switch (name)
                {
                    case "username": user._username = reader.GetString(i);
                        break;
                    case "user_id": user._userId = reader.GetInt32(i);
                        break;
                    case "passwd": user._encodedPassword = reader.GetString(i);
                        break;
                    case "firstname": user._firstname = reader.GetString(i);
                        break;
                    case "surname": user._surname = reader.GetString(i);
                        break;
                    case "role_id": user._roleId = reader.GetInt32(i);
                        break;
                    case "branch_id": user._branchID = reader.GetInt32(i);
                        break;
                    case "is_valid": user._isValid = reader.GetInt32(i) > 0 ? true : false;
                        break;

                    // helper info
                    case "branch_name": user._branchName = reader.GetString(i);
                        break;

                }
            }
            return reader.HasRows;
        }
예제 #3
0
파일: Branch.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Branch branch)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "branch_id": branch._branchID = reader.GetInt32(i);
                                      break;
                    case "branch_name": branch._branchName = reader.GetString(i);
                                      break;
                    case "branch_code": branch._branchCode = reader.GetString(i);
                                      break;
                    case "address": branch._address = reader.GetString(i);
                                      break;
                    case "tel": branch._tel = reader.GetString(i);
                                      break;
                    case "img": branch._img = reader.GetString(i);
                                      break;
                    case "supervisor": branch._supervisor = reader.GetString(i);
                                      break;
                }
            }
            return reader.HasRows;
        }
        private static OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> list            = new List <OdbcParameter>();
            CMDWrapper           statementHandle = command.GetStatementHandle();
            OdbcStatementHandle  hrHandle        = statementHandle.StatementHandle;
            string leftQuote = connection.QuoteChar("DeriveParameters");

            string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, leftQuote, leftQuote, '.', 4, true, "ODBC_ODBCCommandText", false);
            if (strArray[3] == null)
            {
                strArray[3] = command.CommandText;
            }
            ODBC32.RetCode retcode = hrHandle.ProcedureColumns(strArray[1], strArray[2], strArray[3], null);
            if (retcode != ODBC32.RetCode.SUCCESS)
            {
                connection.HandleError(hrHandle, retcode);
            }
            using (OdbcDataReader reader = new OdbcDataReader(command, statementHandle, CommandBehavior.Default))
            {
                reader.FirstResult();
                int fieldCount = reader.FieldCount;
                while (reader.Read())
                {
                    OdbcParameter item = new OdbcParameter {
                        ParameterName = reader.GetString(3)
                    };
                    switch (reader.GetInt16(4))
                    {
                    case 1:
                        item.Direction = ParameterDirection.Input;
                        break;

                    case 2:
                        item.Direction = ParameterDirection.InputOutput;
                        break;

                    case 4:
                        item.Direction = ParameterDirection.Output;
                        break;

                    case 5:
                        item.Direction = ParameterDirection.ReturnValue;
                        break;
                    }
                    item.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(5))._odbcType;
                    item.Size     = reader.GetInt32(7);
                    switch (item.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        item.ScaleInternal     = (byte)reader.GetInt16(9);
                        item.PrecisionInternal = (byte)reader.GetInt16(10);
                        break;
                    }
                    list.Add(item);
                }
            }
            retcode = hrHandle.CloseCursor();
            return(list.ToArray());
        }
예제 #5
0
        public QuestionEntity read(OdbcDataReader reader)
        {
            var res = new QuestionEntity();
            res.id = reader.GetInt32(0);
            res.ans = reader.GetString(2);


            var choicejson = reader.GetString(3);
            var decoder = new JavaScriptSerializer();
            res.choices = decoder.Deserialize< ArrayList >(choicejson);

            res.imageURL = reader.GetString(4);
            res.statement = reader.GetString(5);
            res.type = getTypeString( reader.GetInt32(1) );

            return res;

        }
예제 #6
0
        public static bool CreateForm(OdbcDataReader reader, PaidGroup paidGroup)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);
                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "paid_group_id": paidGroup._paidGroupID = reader.GetInt32(i);
                                      break;
                    case "name": paidGroup._name = reader.GetString(i);
                                      break;
                    case "current_round": paidGroup._currentRound = reader.GetInt32(i);
                                      break;
                    case "rate_info": paidGroup._rawRateInfo = reader.GetString(i);
                                      paidGroup._rateInfo = PaidRateInfo.Parse(paidGroup._rawRateInfo);
                                      break;

                    // helper info

                }
            }
            return reader.HasRows;
        }
예제 #7
0
파일: Role.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Role role)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "name": role._name = reader.GetString(i);
                                      break;
                    case "role_id": role._roleId = reader.GetInt32(i);
                                      break;
                }
            }
            return reader.HasRows;
        }
예제 #8
0
파일: Teacher.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Teacher teacher)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "teacher_id": teacher._teacherID = reader.GetInt32(i);
                                      break;
                    case "sex": teacher._sex = reader.GetString(i);
                                      break;
                    case "addr": teacher._addr = reader.GetString(i);
                                      break;
                    case "tel": teacher._tel = reader.GetString(i);
                                      break;
                    case "email": teacher._email = reader.GetString(i);
                                      break;
                    case "birthday":
                        teacher._birthday = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "firstname": teacher._firstname = reader.GetString(i);
                                      break;
                    case "surname": teacher._surname = reader.GetString(i);
                                      break;
                    case "citizen_id": teacher._citizenID = reader.GetString(i);
                                      break;
                    case "image": teacher._img = reader.GetString(i);
                                      break;
                    case "subject": teacher._subject = reader.GetString(i);
                                      break;
                    case "is_active": teacher._isActive = reader.GetInt32(i) > 0 ? true : false;
                                      break;

                }
            }
            return reader.HasRows;
        }
예제 #9
0
파일: Payment.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Payment payment)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "course_id": payment._courseID = reader.GetInt32(i);
                                      break;
                    case "sum_all_cost": payment._sumAllCost = reader.GetInt32(i);
                                      break;
                    case "sum_max_payable": payment._sumMaxPayable = reader.GetInt32(i);
                                      break;
                    case "sum_paid_cost": payment._sumPaidCost = reader.GetInt32(i);
                                      break;
                    case "last_paid_date": payment._lastPaidDate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "paid_round": payment._paidRound = reader.GetInt32(i);
                                      break;
                    case "status": payment._status = reader.GetInt32(i);
                                      break;
                    // helper info
                    case "bts_course_id": payment._btsCourseID = reader.GetString(i);
                                      break;
                    case "course_name": payment._courseName = reader.GetString(i);
                                      break;
                    case "course_start_date": payment._courseStartDate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "course_end_date": payment._courseEndDate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "paid_group_id": payment._paidGroupID = reader.GetInt32(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
        // DeriveParametersFromStoredProcedure (
        //  OdbcConnection connection,
        //  OdbcCommand command);
        //
        // Uses SQLProcedureColumns to create an array of OdbcParameters
        //

        static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command) {
            List<OdbcParameter> rParams = new List<OdbcParameter>();

            // following call ensures that the command has a statement handle allocated
            CMDWrapper cmdWrapper = command.GetStatementHandle();
            OdbcStatementHandle hstmt = cmdWrapper.StatementHandle;
            int cColsAffected;

            // maps an enforced 4-part qualified string as follows
            // parts[0] = null  - ignored but removal would be a run-time breaking change from V1.0
            // parts[1] = CatalogName (optional, may be null)
            // parts[2] = SchemaName (optional, may be null)
            // parts[3] = ProcedureName
            //
            string quote = connection.QuoteChar(ADP.DeriveParameters);
            string[] parts = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quote, quote, '.', 4, true, Res.ODBC_ODBCCommandText, false);          
            if (null == parts[3]) { // match everett behavior, if the commandtext is nothing but whitespace set the command text to the whitespace
                parts[3] = command.CommandText;
            }
            // note: native odbc appears to ignore all but the procedure name
            ODBC32.RetCode retcode = hstmt.ProcedureColumns(parts[1], parts[2], parts[3], null);

            // Note: the driver does not return an error if the given stored procedure does not exist
            // therefore we cannot handle that case and just return not parameters.

            if (ODBC32.RetCode.SUCCESS != retcode) {
                connection.HandleError(hstmt, retcode);
            }

            using (OdbcDataReader reader = new OdbcDataReader(command, cmdWrapper, CommandBehavior.Default)) {
                reader.FirstResult();
                cColsAffected = reader.FieldCount;

                // go through the returned rows and filter out relevant parameter data
                //
                while (reader.Read()) {
                    // devnote: column types are specified in the ODBC Programmer's Reference
                    // COLUMN_TYPE      Smallint    16bit
                    // COLUMN_SIZE      Integer     32bit
                    // DECIMAL_DIGITS   Smallint    16bit
                    // NUM_PREC_RADIX   Smallint    16bit

                    OdbcParameter parameter = new OdbcParameter();

                    parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME-1);
                    switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE-1)){
                        case ODBC32.SQL_PARAM.INPUT:
                            parameter.Direction = ParameterDirection.Input;
                            break;
                        case ODBC32.SQL_PARAM.OUTPUT:
                            parameter.Direction = ParameterDirection.Output;
                            break;

                        case ODBC32.SQL_PARAM.INPUT_OUTPUT:
                            parameter.Direction = ParameterDirection.InputOutput;
                            break;
                        case ODBC32.SQL_PARAM.RETURN_VALUE:
                            parameter.Direction = ParameterDirection.ReturnValue;
                            break;
                        default:
                            Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
                            break;
                    }
                    parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE-1))._odbcType;
                    parameter.Size = (int)reader.GetInt32(ODBC32.COLUMN_SIZE-1);
                    switch(parameter.OdbcType){
                        case OdbcType.Decimal:
                        case OdbcType.Numeric:
                            parameter.ScaleInternal = (Byte)reader.GetInt16(ODBC32.DECIMAL_DIGITS-1);
                            parameter.PrecisionInternal = (Byte)reader.GetInt16(ODBC32.NUM_PREC_RADIX-1);
                        break;
                    }
                    rParams.Add (parameter);
                }
            }
            retcode = hstmt.CloseCursor();
            return rParams.ToArray();;
        }
예제 #11
0
        public static bool CreateForm(OdbcDataReader reader, Registration reg)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "regis_id": reg._regisID = reader.GetInt32(i);
                                      break;
                    case "transaction_id": reg._transactionID = reader.GetInt32(i);
                                      break;
                    case "transaction_code": reg._transactionCode = reader.GetString(i);
                                      break;
                    case "regis_date": reg._regisdate = new DateTime(reader.GetDateTime(i).Ticks);
                                      break;
                    case "student_id": reg._studentID = reader.GetInt32(i);
                                      break;
                    case "promotion_id": reg._promotionID = reader.GetInt32(i);
                                      break;
                    case "course_id": reg._courseID = reader.GetInt32(i);
                                      break;
                    case "branch_id": reg._branchID = reader.GetInt32(i);
                                      break;

                    case "full_cost": reg._fullCost = reader.GetInt32(i);
                                      break;
                    case "discounted_cost": reg._discountedCost = reader.GetInt32(i);
                                      break;
                    case "seat_no": reg._seatNo = reader.GetString(i);
                                      break;
                    case "note": reg._note = reader.GetString(i);
                                      break;
                    case "paid_method": reg._paidMethod = reader.GetInt32(i);
                                      break;
                    case "paid_round": reg._paidRound = reader.GetInt32(i);
                                      break;
                    case "paid_date": reg._paiddate = new DateTime(reader.GetDateTime(i).Ticks);
                                      break;
                    case "username": reg._username = reader.GetString(i);
                                      break;
                    case "status": reg._status = reader.GetInt32(i);
                                      break;
                    case "is_paid": reg._isPaid = reader.GetInt32(i) > 0 ? true : false;
                                      break;

                    // helper info
                    case "bts_course_id":
                                      reg._btsCourseID = reader.GetString(i);
                                      break;
                    case "student_firstname":
                                      reg._studentFirstname = reader.GetString(i);
                                      break;
                    case "student_surname":
                                      reg._studentSurname = reader.GetString(i);
                                      break;
                    case "student_school":
                                      reg._studentSchool = reader.GetString(i);
                                      break;
                    case "student_level":
                                      reg._studentLevel = reader.GetInt32(i);
                                      break;
                    case "course_name":
                                      reg._courseName = reader.GetString(i);
                                      break;
                    case "course_type":
                                      reg._courseType = reader.GetString(i);
                                      break;
                    case "course_category":
                                      reg._courseCategotry = reader.GetString(i);
                                      break;
                    case "start_date": reg._courseStart = new DateTime(reader.GetDateTime(i).Ticks);
                                      break;
                    case "end_date": reg._courseEnd = new DateTime(reader.GetDateTime(i).Ticks);
                                      break;

                    case "course_short_name":
                                      reg._courseShortName = reader.GetString(i);
                                      break;
                    case "branch_code":
                                      reg._branchCode = reader.GetString(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
예제 #12
0
파일: Database.cs 프로젝트: mansehr/DGP
        public bool testNameAndPassword(string name, string password, Client client)
        {
            try
            {
                int itsInloggId;
                itsCommand = new OdbcCommand("",itsConnection);
                itsCommand.CommandText = "SELECT userID FROM users WHERE email=\'"+ name + "\'";
                itsDataReader =  itsCommand.ExecuteReader();
                if(itsDataReader.Read())
                {
                    itsInloggId = itsDataReader.GetInt32(0);
                    itsDataReader.Close();
                }
                else
                {
                    itsCommand.Dispose();
                    itsDataReader.Close();
                    return false;
                }

                itsCommand.CommandText = "SELECT password FROM users WHERE userID=\'"+ itsInloggId.ToString() + "\'";
                itsDataReader =  itsCommand.ExecuteReader();
                itsDataReader.Read();
                string databasePassword = itsDataReader.GetString(0);
                if(string.Compare(databasePassword, password, true) == 0)
                {
                    itsDataReader.Close();

                    itsCommand.CommandText = "SELECT * FROM users WHERE userID=\'"+ itsInloggId.ToString() + "\'";
                    itsDataReader =  itsCommand.ExecuteReader();
                    itsDataReader.Read();

                    client.Id = itsDataReader.GetString(0);
                    client.Email = name;
                    //client.IpNumber = itsDataReader.GetString(3);
                    client.DisplayName = itsDataReader.GetString(4);

                    itsCommand.Dispose();
                    itsDataReader.Close();
                    return true;
                }
                else
                {
                    itsCommand.Dispose();
                    itsDataReader.Close();
                    return false;
                }
            }
            catch (OdbcException MyOdbcException)//Catch any ODBC exception ..
            {
                this.handleException(MyOdbcException);
            }
            return false;
        }
예제 #13
0
파일: Database.cs 프로젝트: mansehr/DGP
 public int readInt( string sqlCommand)
 {
     try
     {
         int returnInt = 0;
         itsCommand = new OdbcCommand("", itsConnection);
         itsCommand.CommandText = sqlCommand;
         itsDataReader = itsCommand.ExecuteReader();
         while(itsDataReader.Read())
         {
             returnInt = itsDataReader.GetInt32(0);
         }
         itsCommand.Dispose();
         itsDataReader.Close();
         return returnInt;
     }
     catch (OdbcException MyOdbcException)//Catch any ODBC exception ..
     {
         this.handleException(MyOdbcException);
     }
     return 0;
 }
예제 #14
0
파일: Storage.cs 프로젝트: dbazile/blog-cs
        /** Construct a Story from an OdbcDataReader
         ** @param OdbcDataReader result
         ** @return Model
        **/
        public static Model __constructStory(OdbcDataReader result)
        {
            try {

                // Look up Author
                Author author;
                string handle = result.GetString(3);
                OdbcParameter parameter = new OdbcParameter(":handle", handle);
                author = (Author)getSingle(new Author(), "handle=?", parameter);

                return new Story {
                    storyid   = result.GetString(0),
                    timestamp = (long)result.GetInt32(1),
                    permalink = result.GetString(2),
                    author    = author,
                    subject   = result.GetString(4),
                    body      = result.GetString(5)
                };

            } catch (OdbcException e) {
                __fail("SQL Operation Failed", e);
            }

            return null;
        }
예제 #15
0
파일: Course.cs 프로젝트: nettatata/btsman
        public static bool CreateForm(OdbcDataReader reader, Course course)
        {
            if (course._teacher == null) { course._teacher = new Teacher(); }
            if (course._paidGroup == null) { course._paidGroup = new PaidGroup(); }

            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "course_id": course._courseID = reader.GetInt32(i);
                                      break;
                    case "bts_course_id": course._btsCourseID = reader.GetString(i);
                                      break;
                    case "course_name": course._courseName = reader.GetString(i);
                                      break;
                    case "short_name": course._shortName = reader.GetString(i);
                                      break;
                    case "course_desc": course._courseDesc = reader.GetString(i);
                                      break;
                    case "course_type": course._courseType = reader.GetString(i);
                                      break;
                    case "room_id": course._roomID = reader.GetInt32(i);
                                      break;
                    case "teacher_id": course._teacherID = reader.GetInt32(i);
                                      course._teacher._teacherID = course._teacherID;
                                      break;
                    case "paid_group_id": course._paidGroupID = reader.GetInt32(i);
                                      course._paidGroup._paidGroupID = course._paidGroupID;
                                      break;
                    case "category": course._category = reader.GetString(i);
                                      break;
                    case "start_date": course._startdate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "end_date": course._enddate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "day_of_week": course._dayOfWeek = reader.GetString(i);
                                      break;
                    case "open_time": course._opentime = reader.GetString(i);
                                      break;
                    case "cost":      course._cost = reader.GetInt32(i);
                                      course._discountedCost = course._cost;
                                      break;
                    case "seat_limit": course._seatLimit = reader.GetInt32(i);
                                      break;
                    case "bank_regis_limit": course._bankRegisLimit = reader.GetInt32(i);
                                      break;
                    case "image": course._img = reader.GetString(i);
                                      break;
                    case "is_active": course._isActive = reader.GetInt32(i) > 0 ? true : false;
                                      break;
                    // helper info
                    case "teacher_firstname":
                                      course._teacher._firstname = reader.GetString(i);
                                      break;
                    case "teacher_surname":
                                      course._teacher._surname = reader.GetString(i);
                                      break;
                    case "num_registered":
                                      course._numRegistered = reader.GetInt32(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
        private static OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List<OdbcParameter> list = new List<OdbcParameter>();
            CMDWrapper statementHandle = command.GetStatementHandle();
            OdbcStatementHandle hrHandle = statementHandle.StatementHandle;
            string leftQuote = connection.QuoteChar("DeriveParameters");
            string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, leftQuote, leftQuote, '.', 4, true, "ODBC_ODBCCommandText", false);
            if (strArray[3] == null)
            {
                strArray[3] = command.CommandText;
            }
            ODBC32.RetCode retcode = hrHandle.ProcedureColumns(strArray[1], strArray[2], strArray[3], null);
            if (retcode != ODBC32.RetCode.SUCCESS)
            {
                connection.HandleError(hrHandle, retcode);
            }
            using (OdbcDataReader reader = new OdbcDataReader(command, statementHandle, CommandBehavior.Default))
            {
                reader.FirstResult();
                int fieldCount = reader.FieldCount;
                while (reader.Read())
                {
                    OdbcParameter item = new OdbcParameter {
                        ParameterName = reader.GetString(3)
                    };
                    switch (reader.GetInt16(4))
                    {
                        case 1:
                            item.Direction = ParameterDirection.Input;
                            break;

                        case 2:
                            item.Direction = ParameterDirection.InputOutput;
                            break;

                        case 4:
                            item.Direction = ParameterDirection.Output;
                            break;

                        case 5:
                            item.Direction = ParameterDirection.ReturnValue;
                            break;
                    }
                    item.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE) reader.GetInt16(5))._odbcType;
                    item.Size = reader.GetInt32(7);
                    switch (item.OdbcType)
                    {
                        case OdbcType.Decimal:
                        case OdbcType.Numeric:
                            item.ScaleInternal = (byte) reader.GetInt16(9);
                            item.PrecisionInternal = (byte) reader.GetInt16(10);
                            break;
                    }
                    list.Add(item);
                }
            }
            retcode = hrHandle.CloseCursor();
            return list.ToArray();
        }
예제 #17
0
        // DeriveParametersFromStoredProcedure (
        //  OdbcConnection connection,
        //  OdbcCommand command);
        //
        // Uses SQLProcedureColumns to create an array of OdbcParameters
        //

        static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> rParams = new List <OdbcParameter>();

            // following call ensures that the command has a statement handle allocated
            CMDWrapper          cmdWrapper = command.GetStatementHandle();
            OdbcStatementHandle hstmt      = cmdWrapper.StatementHandle;
            int cColsAffected;

            // maps an enforced 4-part qualified string as follows
            // parts[0] = null  - ignored but removal would be a run-time breaking change from V1.0
            // parts[1] = CatalogName (optional, may be null)
            // parts[2] = SchemaName (optional, may be null)
            // parts[3] = ProcedureName
            //
            string quote = connection.QuoteChar(ADP.DeriveParameters);

            string[] parts = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quote, quote, '.', 4, true, Res.ODBC_ODBCCommandText, false);
            if (null == parts[3])
            { // match Everett behavior, if the commandtext is nothing but whitespace set the command text to the whitespace
                parts[3] = command.CommandText;
            }
            // note: native odbc appears to ignore all but the procedure name
            ODBC32.RetCode retcode = hstmt.ProcedureColumns(parts[1], parts[2], parts[3], null);

            // Note: the driver does not return an error if the given stored procedure does not exist
            // therefore we cannot handle that case and just return not parameters.

            if (ODBC32.RetCode.SUCCESS != retcode)
            {
                connection.HandleError(hstmt, retcode);
            }

            using (OdbcDataReader reader = new OdbcDataReader(command, cmdWrapper, CommandBehavior.Default))
            {
                reader.FirstResult();
                cColsAffected = reader.FieldCount;

                // go through the returned rows and filter out relevant parameter data
                //
                while (reader.Read())
                {
                    // devnote: column types are specified in the ODBC Programmer's Reference
                    // COLUMN_TYPE      Smallint    16bit
                    // COLUMN_SIZE      Integer     32bit
                    // DECIMAL_DIGITS   Smallint    16bit
                    // NUM_PREC_RADIX   Smallint    16bit

                    OdbcParameter parameter = new OdbcParameter();

                    parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME - 1);
                    switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE - 1))
                    {
                    case ODBC32.SQL_PARAM.INPUT:
                        parameter.Direction = ParameterDirection.Input;
                        break;

                    case ODBC32.SQL_PARAM.OUTPUT:
                        parameter.Direction = ParameterDirection.Output;
                        break;

                    case ODBC32.SQL_PARAM.INPUT_OUTPUT:
                        parameter.Direction = ParameterDirection.InputOutput;
                        break;

                    case ODBC32.SQL_PARAM.RETURN_VALUE:
                        parameter.Direction = ParameterDirection.ReturnValue;
                        break;

                    default:
                        Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
                        break;
                    }
                    parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE - 1))._odbcType;
                    parameter.Size     = (int)reader.GetInt32(ODBC32.COLUMN_SIZE - 1);
                    switch (parameter.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        parameter.ScaleInternal     = (Byte)reader.GetInt16(ODBC32.DECIMAL_DIGITS - 1);
                        parameter.PrecisionInternal = (Byte)reader.GetInt16(ODBC32.NUM_PREC_RADIX - 1);
                        break;
                    }
                    rParams.Add(parameter);
                }
            }
            retcode = hstmt.CloseCursor();
            return(rParams.ToArray());;
        }
        // DeriveParametersFromStoredProcedure (
        //  OdbcConnection connection,
        //  OdbcCommand command);
        //
        // Uses SQLProcedureColumns to create an array of OdbcParameters
        //

        static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            ArrayList rParams = new ArrayList();

            // following call ensures that the command has a statement handle allocated
            HandleRef hstmt = command.GetStatementHandle();
            int       cColsAffected;

            ODBC32.RETCODE retcode;

            retcode = (ODBC32.RETCODE)UnsafeNativeMethods.Odbc32.SQLProcedureColumnsW(
                hstmt,
                null, 0,
                null, 0,
                command.CommandText, (Int16)ODBC32.SQL_NTS,
                null, 0);

            // Note: the driver does not return an error if the given stored procedure does not exist
            // therefore we cannot handle that case and just return not parameters.

            if (ODBC32.RETCODE.SUCCESS != retcode)
            {
                connection.HandleError(hstmt, ODBC32.SQL_HANDLE.STMT, retcode);
            }

            OdbcDataReader reader = new OdbcDataReader(command, command._cmdWrapper, CommandBehavior.Default);

            reader.FirstResult();
            cColsAffected = reader.FieldCount;

            // go through the returned rows and filter out relevant parameter data
            //
            while (reader.Read())
            {
                OdbcParameter parameter = new OdbcParameter();

                parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME - 1);
                switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE - 1))
                {
                case ODBC32.SQL_PARAM.INPUT:
                    parameter.Direction = ParameterDirection.Input;
                    break;

                case ODBC32.SQL_PARAM.OUTPUT:
                    parameter.Direction = ParameterDirection.Output;
                    break;

                case ODBC32.SQL_PARAM.INPUT_OUTPUT:
                    parameter.Direction = ParameterDirection.InputOutput;
                    break;

                case ODBC32.SQL_PARAM.RETURN_VALUE:
                    parameter.Direction = ParameterDirection.ReturnValue;
                    break;

                default:
                    Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
                    break;
                }
                parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE - 1))._odbcType;
                parameter.Size     = reader.GetInt32(ODBC32.COLUMN_SIZE - 1);
                switch (parameter.OdbcType)
                {
                case OdbcType.Decimal:
                case OdbcType.Numeric:
                    parameter.Scale     = (Byte)reader.GetInt32(ODBC32.DECIMAL_DIGITS - 1);
                    parameter.Precision = (Byte)reader.GetInt32(ODBC32.NUM_PREC_RADIX - 1);
                    break;
                }
                rParams.Add(parameter);
            }

            retcode = (ODBC32.RETCODE)UnsafeNativeMethods.Odbc32.SQLCloseCursor(hstmt);

            // Create a new Parameter array and copy over the ArrayList items
            //
            OdbcParameter[] pList = new OdbcParameter[rParams.Count];
            for (int i = 0; i < rParams.Count; i++)
            {
                pList[i] = (OdbcParameter)rParams[i];
            }

            return(pList);
        }
예제 #19
0
        public static bool CreateForm(OdbcDataReader reader, PaymentHistory paymentHistory)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name)
                {
                    case "payment_id": paymentHistory._paymentID = reader.GetInt32(i);
                        break;
                    case "course_id": paymentHistory._courseID = reader.GetInt32(i);
                        break;
                    case "paid_cost": paymentHistory._paidCost = reader.GetInt32(i);
                        break;
                    case "paid_date": paymentHistory._paidDate = new DateTime(reader.GetDateTime(i).Ticks);
                        break;
                    case "sum_all_cost": paymentHistory._sumAllCost = reader.GetInt32(i);
                        break;
                    case "sum_max_payable": paymentHistory._sumMaxPayable = reader.GetInt32(i);
                        break;
                    case "sum_paid_cost": paymentHistory._sumPaidCost = reader.GetInt32(i);
                        break;
                    case "cost_info": paymentHistory._costInfo = reader.GetString(i);
                        break;
                    case "paid_round": paymentHistory._paidRound = reader.GetInt32(i);
                        break;
                    case "receiver_teacher_id": paymentHistory._receiverTeacherID = reader.GetInt32(i);
                        break;
                    case "username": paymentHistory._username = reader.GetString(i);
                        break;
                    case "branch_id": paymentHistory._branchID = reader.GetInt32(i);
                        break;

                    // helper info
                }
            }
            return reader.HasRows;
        }