Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Weird scenario with INSERT
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01410932
Message ID:
01411035
Vues:
39
>>>Jon, what is the reason for not specifying all columns in the INSERT? That is the standard way and then you don't have to worry about mystery values getting in.
>>
>>Mike,
>>
>>I understand where you're coming from on this, and it's certainly a valid way to resolve what we've been seeing.
>>
>>The main argument I see against this is that if the table in question ever has a structure change, then we would have to make at least one source code change to take into account the structure change, which isn't a very dynamic way to handle things. Given how I've always understood the INSERT command to work, you should not need to specify all fields in the field/value list, because the default values should kick in for all fields that are not specified. If I would be specifying all fields all the time, then I feel there's really no point in supporting default field values.
>>
>>Jon
>
>Jon,
>
>I believe you're correct. I just found a very strange behavior in the program I created.
>
>I had this code
>
>
>IF FIELD("MakeID","Manufacturers") = 0
>			   SELECT * FROM Manufacturers ORDER BY Name INTO CURSOR cM nofilter
>			   ZAP IN Manufacturers
>			   ALTER TABLE Manufacturers ADD COLUMN MakeID I AUTOINC PRIMARY KEY 
>			   INSERT INTO Manufacturers ;
>			   (Name, Compname, Address1, Address2, City, State, Zip, ;
>			   Contact1, Email1, Phone1, Fax1, Contact2, Email2, Phone2, Fax2, ;
>			   Url, Notes, Adduser, Adddate, Changeuser, ;
>			   Changedate, Logo, Website, Licensekey) ;
>			   SELECT Name, Compname, Address1, Address2, City, State, Zip, ;
>			   Contact1, Email1, Phone1, Fax1, Contact2, Email2, Phone2, Fax2, ;
>			   Url, Notes, Adduser, Adddate, Changeuser, Changedate, Logo, ;
>			   Website, Licensekey FROM cM
>			   USE IN SELECT('cM')
>            ENDIF
>
>Originally by mistake I added MakeID in the above statements, as
>
>   INSERT INTO Manufacturers ;
>			   (MakeID, Name, Compname, Address1, Address2, City, State, Zip, ;
>			   Contact1, Email1, Phone1, Fax1, Contact2, Email2, Phone2, Fax2, ;
>			   Url, Notes, Adduser, Adddate, Changeuser, ;
>			   Changedate, Logo, Website, Licensekey) ;
>			   SELECT MakeID, Name, Compname, Address1, Address2, City, State, Zip, ;
>			   Contact1, Email1, Phone1, Fax1, Contact2, Email2, Phone2, Fax2, ;
>			   Url, Notes, Adduser, Adddate, Changeuser, Changedate, Logo, ;
>			   Website, Licensekey FROM cM
>
>
>The result was very weird. The field MakeID became character 40 and the last field LicenseKey was dropped from the table.
>
>May be you have some weird situation like this as well - you think you have some field in the cursor, but you don't.

That's why you should specify the field names as well as the values. Also standard ;-)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform