Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,812

    [Table Editor 0.81 Beta] modifica campi e null

    una grave carenza del programma è quella di non settare il campo, durante una modifica,
    alla possibilità che questo sia nullo (richiesto si/no)
    ovvero, se si spunta o meno "Accept Nulls?", questo comunque viene settato a "no"

    qualcuno sa dove metter mano esattamente,
    prima che mi debba studiare tutto il programma?

    dimenticavo: lavoro su DB access

  2. #2
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,812
    la pagina dev'esser questa.
    che manca?
    codice:
     <%
    	'==============================================================
    	' TableEditoR 0.81 Beta
    	' http://www.2enetworx.com/dev/projects/tableeditor.asp
    	'--------------------------------------------------------------
    	' File: te_fieldedit.asp
    	' Description: Adds or edits a field in a table
    	' Initiated By Hakan Eskici on Nov 15, 2000
    	'--------------------------------------------------------------
    	' Copyright (c) 2002, 2eNetWorX/dev.
    	'
    	' TableEditoR is distributed with General Public License.
    	' Any derivatives of this software must remain OpenSource and
    	' must be distributed at no charge.
    	' (See license.txt for additional information)
    	'
    	' See Credits.txt for the list of contributors.
    	'
    	' Change Log:
    	'-------------------------------------------------------------
    	' # Nov 21, 2000 by Hakan Eskici
    	' Fixed a bug regarding the index to be in the specified table
    	' Added the check to see if a field is indexed (not being a PK)
    	' Added sSQL2 to create an index not being a constraint
    	' # Nov 27, 2000 by Hakan Eskici
    	' Changed sql data type mappings for memo and boolean
    	' # May 11, 2002 by Hakan Eskici
    	' Small fixes for autoincrement, unique and primary key issues
    	' # May 30, 2002 by Rami Kattan
    	' Security check if user can add fields
    	' Security fix, fieldedit require that user have the TableEdit permission too
    	' Fix bug: DSN and SQL cannot show autoincrement with ADOX
    	'==============================================================
    %>
    
    <%
    
    	sub ShowFieldForm
    		if sName = "" then sName = sNewName
    %>
    	
    	
    	<table border=0 cellspacing=1 cellpadding=2 bgcolor = "#ffe4b5" width=100%>
    		<tr>
    			<td class="smallertext">
    				Home  Connections  "><%=arrDesc(request("cid"))%>  &tablename=<%=server.urlencode(request("tablename"))%>">Edit Table [<%=request("tablename")%>]  Edit Field
    			</td>
    			<td class="smallerheader" width=130 align=right>
    			<%
    			if bProtected then 
    				response.write session("teFullName")
    				response.write " (logout)" 
    			end if
    			%>
    			</td>
    		</tr>
    	</table>
    	
    
    	<% if (bFldEdit or bFldAdd) and bTableEdit then	%>
    	<p class="smallertext"><%=sErr%></p>
    	<form action="te_fieldedit.asp?cid=<%=lConnID%>&tablename=<%=sTableName%>&fldname=<%=sName%>" method="post">
    		<table border=0 width=400>
    			<tr>
    				<td class="smallerheader">Name</td>
    				<td><input type="text" name="txtName" class="tbflat" value="<%=sName%>"></td>
    			</tr>
    			<tr>
    				<td class="smallerheader">Type</td>
    				<td>
    					<select name="cboType" class="tbflat">
    					<%
    					for iTemp = 1 to 10
    						response.write "<option value=""" & aT(iTemp,1) & """"
    						if lType = aT(iTemp,1) then
    							response.write " selected>"
    						else
    							response.write ">" 
    						end if
    						response.write aT(iTemp,2)
    					next
    					%>
    					</select>
    				</td>
    			</tr>
    			<tr>
    				<td class="smallerheader">Size (if text)</td>
    				<td><input type="text" name="txtSize" value="<%=lSize%>" size="5" maxlength="10" class="tbflat"></td>
    			</tr>
    			<tr>
    				<td class="smallerheader" valign=top>Attributes</td>
    				<td class="smallertext">
    					<input type="checkbox" name="chkAcceptNulls" value="1"<%=sAcceptNulls%>>Accept Nulls?
    
    					<input type="checkbox" name="chkIndexed" value="1"<%=sIndexed%>>Indexed? 
    
    					<input type="checkbox" name="chkIndexUnique" value="1"<%=sIndexUnique%>>Unique? 
    
    					<input type="checkbox" name="chkPrimaryKey" value="1"<%=sPrimaryKey%>>Primary Key?
    
    					<input type="checkbox" name="chkAutoIncrement" value="1"<%=sAutoIncrement%>>Auto Increment? (if numeric)<% if sNote <> "" then response.write " *"%>
    
    				</td>
    			</tr>
    			<tr>
    				<td></td>
    				<td><input type="submit" name="cmdSave" value=" Save " class="cmdflat"></td>
    			</tr><%
    		if sNote <> "" then response.write "<tr><td colspan=2><p class=""smallertext"">" & sNote & "</p></td></tr>"
    	%>
    			</table>
    		</form>
    <%
    			else
    				Response.Write "<p class=""smallerheader"">You have no permission to add/edit fields</p>"
    			end if
    	end sub
    
    	dim aT(10,2)
    
    	aT(1,1) = adVarWChar		:aT(1,2) = "text"
    	aT(2,1) = adInteger			:aT(2,2) = "long"
    	aT(3,1) = adSmallInt		:aT(3,2) = "integer"
    	aT(4,1) = adBoolean			:aT(4,2) = "boolean"
    	aT(5,1) = adDate			:aT(5,2) = "date"
    	aT(6,1) = adCurrency		:aT(6,2) = "currency"
    	aT(7,1) = adLongVarWChar	:aT(7,2) = "memo"
    	aT(8,1) = adLongVarBinary	:aT(8,2) = "ole"
    	aT(9,1) = adGUID			:aT(9,2) = "guid"
    	aT(10,1)= adUnsignedTinyInt	:aT(10,2)= "byte"
    	
    	lConnID = request("cid")
    	sTableName = request("tablename")
    	sName = request("fldname")
    	if sName = "" then bNewField = True
    	
    	'on error resume next	
    
    	if request("cmdSave") <> "" and (bFldEdit or bFldAdd) then
    		'Submitted new field definition
    		
    		OpenRS arrConn(lConnID)
    		
    		sNewName = request("txtName")
    		sBefore = request("txtBefore")
    		lType = CLng(request("cboType"))
    		if request("txtSize") <> "" then lSize = CLng(request("txtSize"))
    		if request("chkAutoIncrement") <> "" then sAutoIncrement = " checked" 
    		if request("chkAcceptNulls") <> "" then sAcceptNulls = " checked"
    		if request("chkPrimaryKey") <> "" then sPrimaryKey = " checked"
    		if request("chkIndexed") <> "" then sIndexed = " checked"
    		if request("chkIndexUnique") <> "" then sIndexUnique = " checked"
    		
    		sSQL = "ALTER TABLE [" & sTableName & "] "
    		
    		if bNewField then
    			'We are adding a new field
    			sSQL = sSQL & " ADD COLUMN [" & sNewName & "] "
    		else
    			'We are editing a field
    			sSQL = sSQL & " ALTER COLUMN [" & sName & "] "
    		end if
    		
    		select case lType
    			case adSmallInt			: sFieldType = "SMALLINT"
    			case adInteger			: sFieldType = "INTEGER"
    			case adBoolean			: sFieldType = "BIT"
    			case adDate				: sFieldType = "DATE"
    			case adCurrency			: sFieldType = "CURRENCY"
    			case adVarWChar			: sFieldType = "VARCHAR"
    			case adLongVarWChar		: sFieldType = "TEXT"
    			case adLongVarBinary	: sFieldType = "LONGVARBINARY"
    			case adGUID				: sFieldType = "GUID"
    			case adUnsignedTinyInt	: sFieldType = "TINYINT"
    		end select
    		
    		sSQL = sSQL & sFieldType
    		
    		if lType = adVarWChar then
    			'Set field size
    			if lSize = "" then lSize = 50
    			sSQL = sSQL & "(" & lSize & ") "
    		end if
    		
    		if sAcceptNulls <> "" then
    			sSQL = sSQL & " NULL "
    		else
    			sSQL = sSQL & " NOT NULL "
    		end if
    		
    		if sAutoIncrement <> "" then
    			sSQL = sSQL & " IDENTITY "
    		end if
    
    		if sPrimaryKey <> "" then
    			'If the field has a primary key index
    			sSQL = sSQL & " CONSTRAINT [pk" & sNewName & "] PRIMARY KEY "
    		else
    			'If the field is indexed (not PK)
    			if sIndexed <> "" then
    				if sIndexUnique <> "" then
    					sSQL = sSQL & " CONSTRAINT [idx" & sNewName & "] UNIQUE"
    				else
    					'Index is no constraint, so another sql stat required
    					sSQL2 = "CREATE INDEX [idx" & sNewName & "] ON [" & sTableName & "] ([" & sNewName & "]) "
    				end if
    			end if
    		end if
    		
    		if (sName <> "") and (sNewName <> sName) then
    			'Rename field
    			'sSQL = "ALTER TABLE [" & sTableName & "] ALTER COLUMN RENAME [" & sName & "] TO [" & sNewName & "]"
    			sErr = "Cannot rename field."
    			bErr = True
    		end if
    		
    		if bErr = True then
    			conn.close
    			set rs = nothing
    			set conn = nothing
    			ShowFieldForm
    		else
    '			response.write sSQL
    			conn.execute sSQL 
    			if sSQL2 <> "" then
    				conn.execute sSQL2
    			end if
    	
    			conn.close
    			set rs = nothing
    			set conn = nothing
    			if err <> 0 then
    				%><%
    				response.write err.description & "
    " & sSQL
    			else
    				response.redirect "te_tableedit.asp?cid=" & lConnID & "&tablename=" & server.urlencode(request("tablename"))
    			end if
    		end if
    
    	else
    		if sName <> "" then
    			'We are editing a field
    			'Get the attributes for the field
    		
    			OpenRS arrConn(lConnID)
    			set AdoX = server.createobject("adox.catalog")
    '			set fld = server.createobject("adox.column")
    	
    			AdoX.ActiveConnection = conn
    			set fld = AdoX.Tables(sTableName).Columns(sName)
    			
    			lType = fld.Type
    			lSize = fld.DefinedSize
    			
    			if (fld.attributes AND adFldIsNullable) = adFldIsNullable then
    				sAcceptNulls = " checked"
    			end if
    			
    			'Enumerate the indices to check that if this field has a primary key'd index
    			set rs = conn.openSchema(adSchemaIndexes)
    			do while not rs.eof
    				if rs("table_name") = sTableName then
    					if (rs("column_name") = fld.Name) then
    						sIndexed = " checked"
    						if (rs("unIque") = True) then
    							sIndexUnique = " checked"
    						end if
    						if (rs("prImary_key") = True) then 
    							sPrimaryKey = " checked"
    						end if
    					end if
    				end if
    				rs.movenext
    			loop
    			
    			if arrType(lConnID) <> tedbAccess then
    					if request.querystring("autoinc") = "1" then
    						sAutoIncrement = " checked disabled"
    					else
    						sAutoIncrement = " disabled"
    					end if
    
    					sNote = "* Cannot change Auto Increment fields."
    			else
    				if fld.properties("Autoincrement") = True then
    					sAutoIncrement = " checked"
    				end if
    			end if
    
    		end if
    		
    		'Show form for a new field definition
    		if bNewField then 
    			sErr = "Add new field."
    		else
    			sErr = "Edit field definition."
    		end if
    		ShowFieldForm
    	end if
    %>

  3. #3
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,812
    dunque...
    dopo un po' di ricerche pare che:
    1) non sia possibile settare questa proprietè in fase di modifica del campo
    2) non si tratta di una "semplce" modifica del campo ma di alterare la tabella

    quindi le soluzioni possibili dovrebbero essere:

    a) ri-costruire una tabela "al volo" importando tutti i dati dalla vecchia (con i problemi del caso)
    b) alterare la tabella come indicato al punto Syntax #1 e non settare (in questo caso) not null
    Modifying column(s) in a table
    Syntax #1

    To modify a column in an existing table, the ALTER TABLE syntax is:

    ALTER TABLE table_name
    MODIFY column_name column_type;

    For example:

    ALTER TABLE supplier
    MODIFY supplier_name varchar2(100) not null;

    This will modify the column called supplier_name to be a data type of varchar2(100) and force the column to not allow null values.
    c'è qualche notaio in sala che può confermare quanto detto?

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Te la do buona... ahahah



    Roby

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.