Documente Academic
Documente Profesional
Documente Cultură
1. Overview............................................................................................................... 3 Brief introduction:............................................................................................... 3 Conversion issues: .............................................................................................. 3 Data conversion: ................................................................................................ 3 Data Access Techniques: ..................................................................................... 3 System design issues: ......................................................................................... 3 Supporting your application: ................................................................................ 3 2. Before the Conversion............................................................................................. 4 2.1. Will Your Application Survive Conversion?.............................................................. 4 2.1.1. Unconvertable specific Functions, Validations, Data access methods: .................... 4 2.1.2. SQL/VFP Capacity limitation: ............................................................................ 5 2.1.3. Normalization:................................................................................................ 5 2.1.4. Navigation Issues: .......................................................................................... 5 2.2. Data Design Issues ............................................................................................. 5 2.2.1. Data Type Differences ..................................................................................... 5 2.2.2. Logical / Integer:............................................................................................ 7 2.2.3. Text / Character: ............................................................................................ 7 2.2.4. Binary / Image: .............................................................................................. 7 2.2.5. Dates: ........................................................................................................... 7 2.3. International Data and Other Issues ..................................................................... 7 2.3.1. International Data .......................................................................................... 7 2.3.2. Row-Level Access vs. Set Access ...................................................................... 8 2.3.3. Paging Issues, and the Mechanics of SQL Data .................................................. 8 2.4. Nulls, Defaults, and Empty Values ........................................................................ 8 2.5. Indexes ............................................................................................................. 9 3. Data Conversion and Data Access Techniques ......................................................... 10 3.1. Data Conversion ............................................................................................... 10 3.1.1. Bulk Copy Program: ...................................................................................... 10 3.1.2. Data Transformation Services: ....................................................................... 10 3.1.3. The VFP Upsizing Wizard ............................................................................... 10 3.1.4. Writing a Custom Converter ........................................................................... 11 4. Data Access Techniques ........................................................................................ 12 4.1. VFP Remote Views: Pluses................................................................................. 12 4.1.1. Easy Conversion: .......................................................................................... 12 4.1.2. Ability to detect update conflicts:.................................................................... 12 4.1.3. Easily switch Backends: ................................................................................. 12 4.1.4. Automatic handling in Data types: .................................................................. 12 4.2. VFP Remote Views: Minuses .............................................................................. 12 4.2.1. VFP View Designer:....................................................................................... 12 4.2.2. Perfomance: ................................................................................................ 13 4.2.3. Requires VFP Database Container:.................................................................. 13 4.2.4. Cant call SQL Stored Procedures: ................................................................... 13 4.2.5. Data changes takes place on a client: ............................................................. 13 4.3. SQL Pass-Through: Pluses ................................................................................. 13 4.3.1. Multiple connection options:........................................................................... 13 4.3.2. Faster than remote views: ............................................................................. 13 4.3.3. Ability to call stored procedures:..................................................................... 13 4.4. SQL Pass-Through: Minuses............................................................................... 14 4.4.1. More work: .................................................................................................. 14 4.4.2. Have to handle update conflicts: .................................................................... 14 4.4.3. Must know more details about backend table structures:................................... 14 4.4.4. Data translation issues: ................................................................................. 14 4.5. ADO Pluses ................................................................................................... 14 1.1. 1.2. 1.3. 1.4. 1.5. 1.6. As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 1 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 2 of 22
1. Overview
1.1. Brief introduction: Name : Rahul Desai Foxpro & VFP experniece: 15+years Desktop Development Manager at Talman Pty. Ltd. Developer of KenSys range of Commercial applications http://www.nationalcom.com Microsoft SQL Server offers the database developer incredible power and flexibility, but learning to work with it is a lot like learning to play chess. The basics are easy, but mastering the product takes some effort. We will not discuss SQL Server in-depth, as there are many excellent books already available on the subject. Instead, we will discuss the basics of migrating. Microsoft Visual FoxPro (VFP) application to a client/server platform, specifically with SQL server as the database. To that end, I will cover the following: 1.2. Conversion issues: What do your users expect, What do you hope to accomplish with the conversion, and Most importantly, can your application be converted? 1.3. Data conversion: What design issues will you face, and What are some of the differences between SQL-stored data and VFP-based data. 1.4. Data Access Techniques: How do you access SQL-stored data from within VFP? We will investigate Remote views, SQL pass-through, ADO And how they compare with each other. 1.5. System design issues: Wh a ta r es o meo f t h emo r ei mp o r t a n tp e r f o r ma n c ea n d me c h a n i c a l i s sues you will need to consider? 1.6. Supporting your application: How to deal with Table changes, Updates to the code, Error reporting, and so on. This topic is often ignored, but is just as critica l a s d e c i d i n gh o wy o u r eg o i n g to get to the data.
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 3 of 22
1 2 3 4
2.1.1. Unconvertable specific Functions, Validations, Data access methods: Are there any VFP-specific functions built into your data access methods or validation routines? Obviously, these will not translate into SQL Server. If VFP-specific functions do exist, where are they hidden? They could be in index keys or the business logic. Older VFP applications often have functions deeply embedded in critical areas of the system. Where is the business logic embedded in your application? Will you be able to alter it to deal with differences in SQL syntax and data access techniques? Business rules in the user interface (UI) can also relate to more trips to the server, As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 4 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 5 of 22
1 2 3 4 5 6
Field Type TimeStamp Logical Logical Memo Char VarChar General General
Sql Server SQL Server Generated Bit TinyBit Text Char Varchar Binary VarBinary Image DateTime DateTime or SmallDateTime
VFP Unreadable binary Data Logical Logical Memo Character Char (Upto VFP Varchar in VFP 9 General General General Date DateTime 8)
Remarks No indexing available Indexing available Data length is of consistent length Data length is Variable For values with the same fixed length For values with Variable length Variable Values in excess of 8K No Date equivalent in SQL- uses DateTime Use different type in SQL depending on the precision requirement
7 8 9
F i r s t I l l d i s c u s st h ed a t at y p e st h a t I c a l l t h e S Q Lo d d i t i e s . T h e s ea r et h ed a t at y p e sf o r w h i c h there are no equivalents in VFP and, therefore, probably will not be used much. The first data type I will discuss is TIMESTAMP, which is a unique, eight-byte binary value generated by SQL Server. Its extensively u s e dt o b r a n d r e c o r d swhen they are created, the value translates into unreadable binary data for VFP. However, in certain circumstances, having a TIMESTAMP column can help increase query performance on an SQL table . The other similar data types are Cursor, Table, Uniqueidentifier. The second data type is CURSOR, which holds a reference to a special SQL data type used to access data at individual row levels. Related to CURSOR is the third type, TABLE, which is used to store result sets for later processing. TABLE is not available for definition within permanent tables (only for temporary tables), and is also used, for example, for processing within a stored procedure. Both of the CURSOR and TABLE data types are resource-intensive and you should use them sparingly. The last data type is UNIQUEIDENTIFIER, which actually is a very useful data type that I will cover later. SQL Server supports all of the other data types that VFP developers are familiar with, but in some odd flavors. Obviously, the first question you have to ask when defining SQL table c o l u mn si sw h a t t y p eo f f i e l dt ou s e . T h en e x t q u e s t i o nt oa s k , a n di f y o uh a v e n t p l a y e da r o u n d with SQL yet this is going to seem a strange question, is what size field? By t h e s i z e o f t h efield I a mn o t r e f e r r i n gt ot h el e n g t ho f t h ef i e l d , t h a t s ad i f f e r e n t i s s u e . I n s t e a d , I a mr e f e r r i n gt ot h e fact that SQL offers several field sizes for a given data type, each with different minimum and maximum capacities.
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 6 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 9 of 22
The second, and Microsoft-r e c o mme n d e do p t i o n , i s t ou s e D a t aT r a n s f o r ma t i o nS e r v i c e s ( D T S ) . DTS has a wide range of options and types of data sources that it can work with. It can be scheduled to run at off-peak hours and can use VB-Script to transform data into the format e x p e c t e db yy o u r t a b l e s . H o w e v e r , y o uc a n t d y n a mi c a l l ya l t e r e x i s t i n gS Q Ld a t a b a s eo b j e c t sa s DTS only imports data. Furthermore, when importing from a VFP data source, DTS uses ODBC, w h i c hd o e s n t p r o p e r l yh a n d l ee mp t yd a t e s t h a t ma yc o mei nf r o my o u r V F Pt a b l e s . There are two other methods, though, that we will look at in more detail: using the VFP upsizing wizard and writing your own data import program. 3.1.3. The VFP Upsizing Wizard Plus: Automatically generates table structures, index, defaults, RI, validation rules etc Minuses: a. Does not upsize free tables b. Does not upsize triggers , Stored procedures as they have VFP centric function calls c. Table/field/index names that are reserved words in SQL will be created using the word plus an underscore
The VFP Upsizing Wizard does a decent job of porting over simple, DBC-bound VFP tables and table data (one of its failings is that it will not import free tables). It will, unlike DTS, generate table s t r u c t u r e s , i n d e x e s , d e f a u l t s , R I i n f o r ma t i o na n dv a l i d a t i o nr u l e s , me a n i n gt h ed a t a b a s ed o e s n t even have to exist in SQL at the point you run the wizard. It will not upsize triggers or stored procedures, which makes sense because these are most likely to have VFP-centric function calls As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 10 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 11 of 22
SPT gives you the ultimate flexibility in terms of what to do with the data. Normally, returned result sets are passed into a VFP cursor; however, with the use of the SQL OUTPUT parameter, single-row results can be passed directly to VFP variables when executing a stored procedure. Y o ud o n t h a v et og e n e r a t ear e s u l t ; statements like INSERT and UPDATE can execute directly against the backend. However, for interactive changes, the data still needs to be sent to the client. 4.4. SQL Pass-Through: Minuses 4.4.1. More work: SPT has its downsides as well, is the top one being that there is more work required on your part. 4.4.2. Have to handle update conflicts: S P Th a sn o n eo f t h e k n o w l e d g e o f h o wt oc o mmu n i c a t er e s u l t sb a c kt ot h es e r v e r . Wh e r et h i s is handled automatically by the remote view, you will have to work out the details of updates and conflict resolution. H e r e sa ne x a mp l e : w h e ny o ufire an SQLEXEC call, the resulting cursor is non-updating, and by t h a t Id o n t me a ny o uc a n t mo d i f yt h ed a t a , i t me a n st h a t i f y o ud omo d i f yt h ed a t ay o ua r e responsible for passing the updates back to the server. To get around this, you can use CURSORSETPROP method calls to tell the cursor how to communicate back to the server. 4.4.3. Must know more details about backend table structures: One other disadvantage is that you are required to know more of the details regarding the backe n dt a b l es t r u c t u r e s . P e r s o n a l l yI d o n t h a v eap r o b l e mw i t ht h i s , a n dw i t ht h ei mp r o v e me n t st o the Enterprise Manager, it is a lot easier to examine the components of an unfamiliar database. 4.4.4. Data translation issues: A more impo r t a n t p r o b l e mi s t h a t y o uma yh a v es o med a t at r a n s l a t i o ni s s u e s . N a me s l i k e O Niel c a nc a u s eap r o b l e m, s i n c et h ed a t ao f t e nn e e d s t ob e w r a p p e d i nas t r i n gt ob ep a s s e db a c kt o the server. 4.5. ADO Pluses ADO is a collection of COM objects published by Microsoft and used to access any data source that has an OLE-D Bp r o v i d e r a v a i l a b l e . T h eP E M sa v a i l a b l ei nA D Oo f f e r al o t o f p o w e r &f l e x i b i l i t yt o the developer, while hiding the complexity of dealing with OLE-DB. 4.5.1. ADO data is available as properties within the RecordSet or Command object ADO is the choice for n -tier development, but shoehorning it into an existing application can be a difficult chore. Most VFP controls will work with ADO recordset objects; ADO data is available as properties within the RecordSet or Command object, so it is easy to use these properties as c o n t r o l d a t as o u r c e s . T h ee x c e p t i o na r eg r i d s , a n dy o u l l h a v et os u b s t i t u t et h i r d -party classes for the native VFP grid control if you want to display ADO-bound data that way. Like SPT, changes to the data can be made on either the client side or server side. However, ADO handles SQL data on either side more like VFP developers are used to. What do I mean by that? As mentioned earlier, SQL is constructed to handle data in sets not in individual records. This is great for batch processing a single command, for instance, can make changes across an entire table but interactive manipulation requires the data to be brought to the client with a As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 14 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 15 of 22
1 2 3
L e t st a l kb r i e f l ya b o u t o n emo r ed e s i g ni s s u ey o u l l h a v et od e a l w i t h , a n dt h a t i sw h a t t od o about errors. Because you are now dealing with at least two levels the client side and the server side your work load for error trapping and reporting has doubled, at a minimum. If you have any kind of mature VFP app, you probably already have the ability to deal with client-side application errors. But surfacing server-side errors are a little more difficult. To begin with, there are really three different types of errors related to the new data layer you h a v ea d d e dw i t hS Q LS e r v e r . T h ef i r s t w e v ed i s c u s s e dal i t t l ea l r e a d y , a n dt h a t i s w h e nt h e r ei s a problem with a connection. Your system will need to know what to do if a connection is severed or times out, which is why having a connection class (or some type of application-level connection handler) is a good idea. Another type of error, which really only applies if you are using SPT, is what to do if SQLEXEC r e t u r n san e g a t i v ev a l u e . I f t h es t a t e me n t y o ut r i e dt op a s sc a n t e x e c u t e , S Q L E X E Cr e t u r n s 1 with no clue as to why this happened. This can really be considered a system bug, and treated as such with ASSERT statements. One habit I have adopted is to always put store the statement to b ee x e c u t e di n t oal o c a l v a r i a b l e , t h e np o pt h a t v a r i a b l e sv a l u ei n t o_ C L I P T E X Ti f t h eS Q L E X E C result is negative (see the EXECUTE() method in the connection class outlined above). This way, you can immediately paste the offending statement into the Query Analyzer to figure out what went wrong. As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 19 of 22
The last type of error problems that may occur on the server side when data is being updated is where you will need to do the most work when modifying your error handling routines. For starters, although VFP knows that an error occurred, the message number returned is always the same (#1526), and the message itself is usually very technical. It may make perfect sense to you, but to a user, it will be incomprehensible. In fact, VFP knows more about the error than is immediately reported, which you can access thru the AERROR() function. The fifth column of the array will give you the SQL Server error number; the second row of the array will tell you what SQL Server did about the offending statement. If y o u r e r r o r h a n d l e r i s n t c a p t u r i n gt h ev a l u eo f t h a t a r r a y , y o u l l n e e dt oi n c l u d ei t . T h e r ei s n t mu c h more you can do here, except to display something a little less scary to the users. One way that you can do that is by customizing the messages that SQL Server itself generates if you are using stored procedures. The RAISERROR command allows you to construct your own error messages o nt h ef l y ,o ry o uc a np e r ma n e n t l yi n s t a l lt h e m i nt h e s y s me s s a g e s t a b l eu s i n gt h e s p _ a d d me s s a g e s s y s t e ms t o r e dp r o c e d u r e .
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 20 of 22
As Presented at OZFOX 25th-26th March 2006 by Rahul Desai. Email: rahul.desai@talman.com.au / rahul@nationalcom.com Page 22 of 22