1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LNoException.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "LConnection.hxx"
36 using namespace connectivity
;
37 using namespace connectivity::evoab
;
39 //------------------------------------------------------------------
40 xub_StrLen
OEvoabString::GetTokenCount( sal_Unicode cTok
, sal_Unicode cStrDel
) const
45 xub_StrLen nTokCount
= 1;
46 BOOL bStart
= TRUE
; // Stehen wir auf dem ersten Zeichen im Token?
47 BOOL bInString
= FALSE
; // Befinden wir uns INNERHALB eines (cStrDel delimited) String?
49 // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
50 for( xub_StrLen i
= 0; i
< Len(); i
++ )
55 // Erstes Zeichen ein String-Delimiter?
56 if ((*this).GetChar(i
) == cStrDel
)
58 bInString
= TRUE
; // dann sind wir jetzt INNERHALB des Strings!
59 continue; // dieses Zeichen ueberlesen!
64 // Wenn jetzt das String-Delimiter-Zeichen auftritt ...
65 if ( (*this).GetChar(i
) == cStrDel
)
67 if ((i
+1 < Len()) && ((*this).GetChar(i
+1) == cStrDel
))
69 // Verdoppeltes String-Delimiter-Zeichen:
70 i
++; // kein String-Ende, naechstes Zeichen ueberlesen.
79 // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
80 if ( (*this).GetChar(i
) == cTok
)
87 //OSL_TRACE("OEvoabString::nTokCount = %d\n", ((OUtoCStr(::rtl::OUString(nTokCount))) ? (OUtoCStr(::rtl::OUString(nTokCount))):("NULL")) );
92 //------------------------------------------------------------------
93 void OEvoabString::GetTokenSpecial( String
& _rStr
,xub_StrLen
& nStartPos
, sal_Unicode cTok
, sal_Unicode cStrDel
) const
96 xub_StrLen nLen
= Len();
99 BOOL bInString
= (nStartPos
< nLen
) && ((*this).GetChar(nStartPos
) == cStrDel
); // Befinden wir uns INNERHALB eines (cStrDel delimited) String?
101 // Erstes Zeichen ein String-Delimiter?
103 ++nStartPos
; // dieses Zeichen ueberlesen!
104 // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
105 for( xub_StrLen i
= nStartPos
; i
< nLen
; ++i
)
109 // Wenn jetzt das String-Delimiter-Zeichen auftritt ...
110 if ( (*this).GetChar(i
) == cStrDel
)
112 if ((i
+1 < nLen
) && ((*this).GetChar(i
+1) == cStrDel
))
114 // Verdoppeltes String-Delimiter-Zeichen:
115 ++i
; // kein String-Ende, naechstes Zeichen ueberlesen.
117 _rStr
+= (*this).GetChar(i
); // Zeichen gehoert zum Resultat-String
127 _rStr
+= (*this).GetChar(i
); // Zeichen gehoert zum Resultat-String
133 // Stimmt das Tokenzeichen ueberein, dann erhoehe nTok
134 if ( (*this).GetChar(i
) == cTok
)
136 // Vorzeitiger Abbruch der Schleife moeglich, denn
137 // wir haben, was wir wollten.
143 _rStr
+= (*this).GetChar(i
); // Zeichen gehoert zum Resultat-String
149 // -----------------------------------------------------------------------------
150 void OEvoabTable::refreshIndexes()
153 // -----------------------------------------------------------------------------
154 sal_Bool
OEvoabTable::checkHeaderLine()
156 if (m_nFilePos
== 0 && ((OEvoabConnection
*)m_pConnection
)->isHeaderLine())
161 bRead2
= m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,m_pConnection
->getTextEncoding());
163 while(bRead2
&& !m_aCurrentLine
.Len());
165 m_nFilePos
= m_pFileStream
->Tell();
166 if (m_pFileStream
->IsEof())
171 //------------------------------------------------------------------
172 sal_Bool
OEvoabTable::seekRow(IResultSetHelper::Movement eCursorPosition
, sal_Int32 nOffset
, sal_Int32
& nCurPos
)
174 //OSL_TRACE("OEvoabTable::(before SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
176 if ( !m_pFileStream
)
178 OEvoabConnection
* pConnection
= (OEvoabConnection
*)m_pConnection
;
179 // ----------------------------------------------------------
180 // Positionierung vorbereiten:
181 //OSL_TRACE("OEvoabTable::(before SeekRow,m_pFileStriam Exist)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
183 m_nFilePos
= nCurPos
;
185 switch(eCursorPosition
)
187 case IResultSetHelper::FIRST
:
191 case IResultSetHelper::NEXT
:
192 if(eCursorPosition
!= IResultSetHelper::FIRST
)
194 m_pFileStream
->Seek(m_nFilePos
);
195 if (m_pFileStream
->IsEof() || !checkHeaderLine())
197 m_nMaxRowCount
= m_nRowPos
;
201 m_aRowToFilePos
.insert(::std::map
<sal_Int32
,sal_Int32
>::value_type(m_nRowPos
,m_nFilePos
));
203 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
204 if (m_pFileStream
->IsEof())
206 m_nMaxRowCount
= m_nRowPos
;
209 nCurPos
= m_pFileStream
->Tell();
211 case IResultSetHelper::PRIOR
:
215 m_nFilePos
= m_aRowToFilePos
.find(m_nRowPos
)->second
;
216 m_pFileStream
->Seek(m_nFilePos
);
217 if (m_pFileStream
->IsEof() || !checkHeaderLine())
219 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
220 if (m_pFileStream
->IsEof())
222 nCurPos
= m_pFileStream
->Tell();
230 case IResultSetHelper::LAST
:
233 m_nFilePos
= m_aRowToFilePos
.rbegin()->second
;
234 m_nRowPos
= m_aRowToFilePos
.rbegin()->first
;
235 m_pFileStream
->Seek(m_nFilePos
);
236 if (m_pFileStream
->IsEof() || !checkHeaderLine())
238 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
239 if (m_pFileStream
->IsEof())
241 nCurPos
= m_pFileStream
->Tell();
245 while(seekRow(IResultSetHelper::NEXT
,1,nCurPos
)) ; // run through after last row
247 seekRow(IResultSetHelper::PRIOR
,1,nCurPos
);
250 case IResultSetHelper::RELATIVE
:
253 for(sal_Int32 i
= 0;i
<nOffset
;++i
)
254 seekRow(IResultSetHelper::NEXT
,1,nCurPos
);
258 for(sal_Int32 i
= nOffset
;i
;++i
)
259 seekRow(IResultSetHelper::PRIOR
,1,nCurPos
);
262 case IResultSetHelper::ABSOLUTE
:
265 nOffset
= m_nRowPos
+ nOffset
;
266 ::std::map
<sal_Int32
,sal_Int32
>::const_iterator aIter
= m_aRowToFilePos
.find(nOffset
);
267 if(aIter
!= m_aRowToFilePos
.end())
269 m_nFilePos
= aIter
->second
;
270 m_pFileStream
->Seek(m_nFilePos
);
271 if (m_pFileStream
->IsEof() || !checkHeaderLine())
273 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
274 if (m_pFileStream
->IsEof())
276 nCurPos
= m_pFileStream
->Tell();
278 else if(m_nMaxRowCount
&& nOffset
> m_nMaxRowCount
) // offset is outside the table
280 m_nRowPos
= m_nMaxRowCount
;
285 aIter
= m_aRowToFilePos
.upper_bound(nOffset
);
286 if(aIter
== m_aRowToFilePos
.end())
288 m_nRowPos
= m_aRowToFilePos
.rbegin()->first
;
289 nCurPos
= m_nFilePos
= m_aRowToFilePos
.rbegin()->second
;
290 while(m_nRowPos
!= nOffset
)
291 seekRow(IResultSetHelper::NEXT
,1,nCurPos
);
296 m_nRowPos
= aIter
->first
;
297 m_nFilePos
= aIter
->second
;
298 m_pFileStream
->Seek(m_nFilePos
);
299 if (m_pFileStream
->IsEof() || !checkHeaderLine())
301 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
302 if (m_pFileStream
->IsEof())
304 nCurPos
= m_pFileStream
->Tell();
310 case IResultSetHelper::BOOKMARK
:
311 m_pFileStream
->Seek(nOffset
);
312 if (m_pFileStream
->IsEof())
315 m_nFilePos
= m_pFileStream
->Tell(); // Byte-Position in der Datei merken (am ZeilenANFANG)
316 m_pFileStream
->ReadByteStringLine(m_aCurrentLine
,pConnection
->getTextEncoding());
317 if (m_pFileStream
->IsEof())
319 nCurPos
= m_pFileStream
->Tell();
323 //OSL_TRACE("OEvoabTable::(after SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
327 // -----------------------------------------------------------------------------