Пример #1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //추가 :
        //목적 : Get Table Information
        //설명 : 테이블 스키마 정보 받음
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private bool HLGetTableInformation(string strTableName, ref DataTable objDataTable)
        {
            bool bReturn = false;

            do
            {
                string       strQuery  = string.Format("pragma table_info({0})", strTableName);
                CErrorReturn objReturn = m_objSQLite.HLReload(strQuery, ref objDataTable);
                if (true == objReturn.m_bError)
                {
                    break;
                }

                bReturn = true;
            } while(false);

            return(bReturn);
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //추가 :
        //목적 : 초기화
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool HLInitialize(CSQLite objSQLite, string strTableFullPath, string strRecordFullPath)
        {
            bool bReturn = false;

            do
            {
                try {
                    // SQLite 이어줌
                    m_objSQLite = objSQLite;
                    // Txt 파일 클래스
                    CTxtFile objTxtFile = new CTxtFile();
                    // 이름 제외한 폴더 경로
                    string strTablePathOnly = Path.GetDirectoryName(strTableFullPath);
                    // 파일 이름 (확장자를 포함)
                    string strTableExtendName = Path.GetFileName(strTableFullPath);
                    // 확장자를 제거한 파일 이름
                    m_strTableName = Path.GetFileNameWithoutExtension(strTableFullPath);
                    // 확장자
                    string strTableExtendOnly = Path.GetExtension(strTableFullPath);
                    // 테이블이 이미 생성되어 있으면 생성 쿼리문 건너뜀
                    bool bExistence = new bool();
                    if (false == HLGetTableExistence(m_strTableName, ref bExistence))
                    {
                        break;
                    }
                    if (false == bExistence)
                    {
                        // 테이블 생성
                        DataTable objDataTable = new DataTable();
                        // .csv 파일은 읽지 않는 걸로 수정
                        if (".txt" == strTableExtendOnly.ToLower())
                        {
                            objDataTable = objTxtFile.GetDataTableFromTxt(string.Format(@"{0}\{1}", strTablePathOnly, strTableExtendName), true);
                        }
                        else
                        {
                            string strThrowLog = string.Format("CManagerTable HLInitialize There is no {0} file.", strTableExtendName);
                            throw new System.ArgumentException(strThrowLog);
                        }
                        if (false == HLSetTableCreate(m_strTableName, objDataTable))
                        {
                            break;
                        }
                    }
                    // 테이블 스키마 정보 얻음
                    DataTable objSchemaInfo = new DataTable();
                    if (false == HLGetTableInformation(m_strTableName, ref objSchemaInfo))
                    {
                        break;
                    }
                    // 테이블 스키마 에트리뷰트 이름, 타입 가져옴
                    DataRow[] objSchemaInfoRow = objSchemaInfo.Select();
                    m_strTableSchemaName = new string[objSchemaInfoRow.Length];
                    m_strTableSchemaType = new string[objSchemaInfoRow.Length];
                    for (int iLoopRow = 0; iLoopRow < objSchemaInfoRow.Length; iLoopRow++)
                    {
                        m_strTableSchemaName[iLoopRow] = objSchemaInfoRow[iLoopRow].ItemArray[( int )enumSchemaInfo.SCHEMA_INFO_NAME].ToString();
                        m_strTableSchemaType[iLoopRow] = objSchemaInfoRow[iLoopRow].ItemArray[( int )enumSchemaInfo.SCHEMA_INFO_TYPE].ToString();
                        // pk에 해당하는 row값 저장
                        if ("1" == objSchemaInfoRow[iLoopRow].ItemArray[( int )enumSchemaInfo.SCHEMA_INFO_PK].ToString())
                        {
                            m_iPkIndex = iLoopRow;
                        }
                    }
                    // 레코드 파일이 있으면 레코드 INSERT 쿼리문 실행
                    if (null != strRecordFullPath && "" != strRecordFullPath)
                    {
                        // 이름 제외한 폴더 경로
                        string strRecordPathOnly = Path.GetDirectoryName(strRecordFullPath);
                        // 파일 이름 (확장자를 포함)
                        string strRecordExtendName = Path.GetFileName(strRecordFullPath);
                        // 확장자를 제거한 파일 이름
                        string strRecordName = Path.GetFileNameWithoutExtension(strRecordFullPath);
                        // 확장자
                        string strRecordExtendOnly = Path.GetExtension(strRecordFullPath);
                        // 레코드 데이터 밀어넣기 전에 테이블에 데이터 삭제
                        if (false == HLSetTableDataDelete(m_strTableName))
                        {
                            break;
                        }
                        // 테이블에 레코드 삽입
                        DataTable objDataTable = new DataTable();
                        // .csv 파일은 읽지 않는 걸로 수정
                        if (".txt" == strRecordExtendOnly.ToLower())
                        {
                            objDataTable = objTxtFile.GetDataTableFromTxt(string.Format(@"{0}\{1}", strRecordPathOnly, strRecordExtendName), true);
                        }
                        else
                        {
                            string strThrowLog = string.Format("CManagerTable HLInitialize There is no {0} file.", strTableExtendName);
                            throw new System.ArgumentException(strThrowLog);
                        }
                        if (false == HLSetTableDataInsert(m_strTableName, objDataTable))
                        {
                            break;
                        }
                    }
                    // 해당 테이블에 전체 Select 결과를 저장
                    string strQuery = string.Format("select * from {0}", m_strTableName);
                    m_objDataTable = new DataTable();
                    m_objSQLite.HLReload(strQuery, ref m_objDataTable);
                }
                catch (Exception ex) {
                    Trace.WriteLine(ex.Message);
                }

                bReturn = true;
            } while(false);

            return(bReturn);
        }